diff --git a/approximations/build.gradle.kts b/approximations/build.gradle.kts index 23559ac0..87774c1f 100644 --- a/approximations/build.gradle.kts +++ b/approximations/build.gradle.kts @@ -1,6 +1,7 @@ plugins { java `maven-publish` + id("org.springframework.boot") version "3.2.0" apply false } repositories { @@ -8,13 +9,18 @@ repositories { maven("https://jitpack.io") } -private val jacodbPackage = "com.github.UnitTestBot.jacodb" -private val jacodbVersion = "890624770b" // jacodb neo branch +private val jacodbPackage = "org.jacodb" +private val jacodbVersion = "00164e304b" // jacodb neo branch dependencies { compileOnly("$jacodbPackage:jacodb-api-jvm:$jacodbVersion") compileOnly("$jacodbPackage:jacodb-approximations:$jacodbVersion") compileOnly(files(rootDir.resolve("usvm-api/usvm-api.jar"))) + compileOnly("org.springframework.boot:spring-boot-starter-web:3.2.0") + compileOnly("org.springframework.boot:spring-boot-starter-test:3.2.0") + compileOnly("org.springframework.boot:spring-boot-starter-data-jpa:3.2.0") + // Fixes "unknown enum constant 'When.MAYBE'" warning + compileOnly("com.google.code.findbugs:jsr305:3.0.2") } group = "org.usvm.approximations.java.stdlib" @@ -28,6 +34,8 @@ tasks.withType { options.compilerArgs.add("-source") options.compilerArgs.add("1.8") options.compilerArgs.add("-Xlint:unchecked") + options.compilerArgs.add("-Xlint:all") + options.compilerArgs.add("-Werror") } publishing { diff --git a/approximations/src/main/java/decoders/java/lang/SecurityManager_Decoder.java b/approximations/src/main/java/decoders/java/lang/SecurityManager_Decoder.java index 7fa402fc..7ed663e1 100644 --- a/approximations/src/main/java/decoders/java/lang/SecurityManager_Decoder.java +++ b/approximations/src/main/java/decoders/java/lang/SecurityManager_Decoder.java @@ -10,7 +10,7 @@ import java.util.Collections; import java.util.List; -@SuppressWarnings("ForLoopReplaceableByForEach") +@SuppressWarnings({"ForLoopReplaceableByForEach", "removal"}) @DecoderFor(SecurityManager.class) public final class SecurityManager_Decoder implements ObjectDecoder { private volatile JcMethod cached_SecurityManager_ctor = null; diff --git a/approximations/src/main/java/decoders/java/util/ArrayList_Decoder.java b/approximations/src/main/java/decoders/java/util/ArrayList_Decoder.java index 162bde35..4e5e3a59 100644 --- a/approximations/src/main/java/decoders/java/util/ArrayList_Decoder.java +++ b/approximations/src/main/java/decoders/java/util/ArrayList_Decoder.java @@ -46,7 +46,7 @@ public T createInstance(final JcClassOrInterface approx, List params = m.getParameters(); if (params.size() != 1) continue; - if (!"java.lang.Object".equals(params.get(0).getType().getTypeName())) continue; + //if (!"java.lang.Object".equals(params.get(0).getType().getTypeName())) continue; cached_ArrayList_add = m_add = m; } @@ -68,7 +68,7 @@ public void initializeInstance(final JcClassOrInterface approx, JcField f_storage = cached_ArrayList_storage; // TODO: add synchronization if needed if (f_storage == null) { - final List fields = approx.getDeclaredFields(); + final List fields = getAllFields(approx); for (int i = 0, c = fields.size(); i < c; i++) { JcField f = fields.get(i); if ("storage".equals(f.getName())) { @@ -93,4 +93,21 @@ public void initializeInstance(final JcClassOrInterface approx, decoder.invokeMethod(cached_ArrayList_add, args); } } + + public List getAllFields(JcClassOrInterface type) { + List typesToCheck = new ArrayList<>(); + typesToCheck.add(type); + List allFields = new ArrayList<>(); + while (!typesToCheck.isEmpty()) { + int lastIndex = typesToCheck.size() - 1; + JcClassOrInterface current = typesToCheck.remove(lastIndex); + allFields.addAll(current.getDeclaredFields()); + + JcClassOrInterface superClass = current.getSuperClass(); + if (superClass != null) { + typesToCheck.add(superClass); + } + } + return allFields; + } } diff --git a/approximations/src/main/java/decoders/java/util/HashSet_Decoder.java b/approximations/src/main/java/decoders/java/util/HashSet_Decoder.java index 0f787250..4a7634ed 100644 --- a/approximations/src/main/java/decoders/java/util/HashSet_Decoder.java +++ b/approximations/src/main/java/decoders/java/util/HashSet_Decoder.java @@ -153,7 +153,7 @@ public void initializeInstance(final JcClassOrInterface approximation, decoder.invokeMethod(m_add, args); map.remove(key); - length -= 1; + length--; } } } diff --git a/approximations/src/main/java/decoders/java/util/LinkedHashSet_Decoder.java b/approximations/src/main/java/decoders/java/util/LinkedHashSet_Decoder.java index 2ba5090a..35c9f296 100644 --- a/approximations/src/main/java/decoders/java/util/LinkedHashSet_Decoder.java +++ b/approximations/src/main/java/decoders/java/util/LinkedHashSet_Decoder.java @@ -153,7 +153,7 @@ public void initializeInstance(final JcClassOrInterface approximation, decoder.invokeMethod(m_add, args); map.remove(key); - length -= 1; + length--; } } } diff --git a/approximations/src/main/java/decoders/java/util/OptionalDouble_Decoder.java b/approximations/src/main/java/decoders/java/util/OptionalDouble_Decoder.java index bc23ed21..0ede685d 100644 --- a/approximations/src/main/java/decoders/java/util/OptionalDouble_Decoder.java +++ b/approximations/src/main/java/decoders/java/util/OptionalDouble_Decoder.java @@ -35,7 +35,7 @@ public T createInstance(final JcClassOrInterface approximation, if ("value".equals(name)) { f_value = f; - } else if ("present".equals(name)) { + } else if ("isPresent".equals(name)) { f_present = f; } @@ -92,4 +92,4 @@ public void initializeInstance(final JcClassOrInterface approximation, final DecoderApi decoder) { // nothing } -} \ No newline at end of file +} diff --git a/approximations/src/main/java/decoders/java/util/OptionalInt_Decoder.java b/approximations/src/main/java/decoders/java/util/OptionalInt_Decoder.java index 0524167c..a38f60d3 100644 --- a/approximations/src/main/java/decoders/java/util/OptionalInt_Decoder.java +++ b/approximations/src/main/java/decoders/java/util/OptionalInt_Decoder.java @@ -36,7 +36,7 @@ public T createInstance(final JcClassOrInterface approx, // NOTE: this is an example on how to join discovery process for multiple targets if ("value".equals(name)) { f_value = f; - } else if ("present".equals(name)) { + } else if ("isPresent".equals(name)) { f_present = f; } if (f_value != null && f_present != null) diff --git a/approximations/src/main/java/decoders/java/util/OptionalLong_Decoder.java b/approximations/src/main/java/decoders/java/util/OptionalLong_Decoder.java index 5863f529..8fb40749 100644 --- a/approximations/src/main/java/decoders/java/util/OptionalLong_Decoder.java +++ b/approximations/src/main/java/decoders/java/util/OptionalLong_Decoder.java @@ -35,7 +35,7 @@ public T createInstance(final JcClassOrInterface approx, if ("value".equals(name)) { f_value = f; - } else if ("present".equals(name)) { + } else if ("isPresent".equals(name)) { f_present = f; } diff --git a/approximations/src/main/java/encoders/java/util/AbstractMap_Entry_Encoder.java b/approximations/src/main/java/encoders/java/util/AbstractMap_Entry_Encoder.java new file mode 100644 index 00000000..2b79b6cd --- /dev/null +++ b/approximations/src/main/java/encoders/java/util/AbstractMap_Entry_Encoder.java @@ -0,0 +1,17 @@ +package encoders.java.util; + +import generated.java.util.map.AbstractMap_EntryImpl; +import org.usvm.api.encoder.EncoderFor; +import org.usvm.api.encoder.ObjectEncoder; +import stub.java.util.map.AbstractMap_Entry; + +import java.util.Map; + +@EncoderFor(AbstractMap_Entry.class) +public class AbstractMap_Entry_Encoder implements ObjectEncoder { + + @Override + public Object encode(Object list) { + return new AbstractMap_EntryImpl<>((Map.Entry) list); + } +} diff --git a/approximations/src/main/java/encoders/java/util/ArrayList_Encoder.java b/approximations/src/main/java/encoders/java/util/ArrayList_Encoder.java new file mode 100644 index 00000000..09904b22 --- /dev/null +++ b/approximations/src/main/java/encoders/java/util/ArrayList_Encoder.java @@ -0,0 +1,18 @@ +package encoders.java.util; + +import generated.java.util.list.ArrayListImpl; +import org.usvm.api.encoder.EncoderFor; +import org.usvm.api.encoder.ObjectEncoder; + +import java.util.ArrayList; + +@EncoderFor(ArrayList.class) +public class ArrayList_Encoder implements ObjectEncoder { + + @Override + public Object encode(Object list) { + ArrayListImpl result = new ArrayListImpl<>(); + result.addAll(((ArrayList) list).stream().toList()); + return result; + } +} diff --git a/approximations/src/main/java/encoders/java/util/ConcurrentHashMap_Encoder.java b/approximations/src/main/java/encoders/java/util/ConcurrentHashMap_Encoder.java new file mode 100644 index 00000000..c66ad9f4 --- /dev/null +++ b/approximations/src/main/java/encoders/java/util/ConcurrentHashMap_Encoder.java @@ -0,0 +1,18 @@ +package encoders.java.util; + +import generated.java.util.map.ConcurrentHashMapImpl; +import org.usvm.api.encoder.EncoderFor; +import org.usvm.api.encoder.ObjectEncoder; + +import java.util.concurrent.ConcurrentHashMap; + +@EncoderFor(ConcurrentHashMap.class) +public class ConcurrentHashMap_Encoder implements ObjectEncoder { + + @SuppressWarnings("unchecked") + @Override + public Object encode(Object object) { + ConcurrentHashMap map = (ConcurrentHashMap) object; + return new ConcurrentHashMapImpl<>(map); + } +} diff --git a/approximations/src/main/java/encoders/java/util/HashMap_Encoder.java b/approximations/src/main/java/encoders/java/util/HashMap_Encoder.java new file mode 100644 index 00000000..e247518f --- /dev/null +++ b/approximations/src/main/java/encoders/java/util/HashMap_Encoder.java @@ -0,0 +1,19 @@ +package encoders.java.util; + +import generated.java.util.map.HashMapImpl; +import org.usvm.api.encoder.EncoderFor; +import org.usvm.api.encoder.ObjectEncoder; + +import java.util.HashMap; + +@SuppressWarnings("unused") +@EncoderFor(HashMap.class) +public class HashMap_Encoder implements ObjectEncoder { + + @SuppressWarnings("unchecked") + @Override + public Object encode(Object object) { + HashMap map = (HashMap) object; + return new HashMapImpl<>(map); + } +} diff --git a/approximations/src/main/java/encoders/java/util/HashSet_Encoder.java b/approximations/src/main/java/encoders/java/util/HashSet_Encoder.java new file mode 100644 index 00000000..5c02fc20 --- /dev/null +++ b/approximations/src/main/java/encoders/java/util/HashSet_Encoder.java @@ -0,0 +1,20 @@ +package encoders.java.util; + +import generated.java.util.set.HashSetImpl; +import org.usvm.api.encoder.EncoderFor; +import org.usvm.api.encoder.ObjectEncoder; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +@EncoderFor(HashSet.class) +public class HashSet_Encoder implements ObjectEncoder { + + @Override + public Object encode(Object object) { + HashSetImpl result = new HashSetImpl<>(); + result.addAll(Arrays.asList(((Set) object).toArray())); + return result; + } +} diff --git a/approximations/src/main/java/encoders/java/util/LinkedHashMap_Encoder.java b/approximations/src/main/java/encoders/java/util/LinkedHashMap_Encoder.java new file mode 100644 index 00000000..1012a65d --- /dev/null +++ b/approximations/src/main/java/encoders/java/util/LinkedHashMap_Encoder.java @@ -0,0 +1,19 @@ +package encoders.java.util; + +import generated.java.util.map.LinkedHashMapImpl; +import org.usvm.api.encoder.EncoderFor; +import org.usvm.api.encoder.ObjectEncoder; + +import java.util.LinkedHashMap; + +@SuppressWarnings("unused") +@EncoderFor(LinkedHashMap.class) +public class LinkedHashMap_Encoder implements ObjectEncoder { + + @SuppressWarnings("unchecked") + @Override + public Object encode(Object object) { + LinkedHashMap map = (LinkedHashMap) object; + return new LinkedHashMapImpl<>(map); + } +} diff --git a/approximations/src/main/java/encoders/java/util/String_Encoder.java b/approximations/src/main/java/encoders/java/util/String_Encoder.java new file mode 100644 index 00000000..d8c3b59c --- /dev/null +++ b/approximations/src/main/java/encoders/java/util/String_Encoder.java @@ -0,0 +1,14 @@ +package encoders.java.util; + +import generated.java.lang.StringImpl; +import org.usvm.api.encoder.EncoderFor; +import org.usvm.api.encoder.ObjectEncoder; + +@EncoderFor(java.lang.String.class) +public class String_Encoder implements ObjectEncoder { + + @Override + public Object encode(Object object) { + return new StringImpl(((String) object).getBytes()); + } +} diff --git a/approximations/src/main/java/encoders/java/util/ThreadLocal_Encoder.java b/approximations/src/main/java/encoders/java/util/ThreadLocal_Encoder.java new file mode 100644 index 00000000..0f5964a7 --- /dev/null +++ b/approximations/src/main/java/encoders/java/util/ThreadLocal_Encoder.java @@ -0,0 +1,14 @@ +package encoders.java.util; + +import generated.java.lang.ThreadLocalImpl; +import org.usvm.api.encoder.EncoderFor; +import org.usvm.api.encoder.ObjectEncoder; + +@EncoderFor(java.lang.ThreadLocal.class) +public class ThreadLocal_Encoder implements ObjectEncoder { + + @Override + public Object encode(Object object) { + return new ThreadLocalImpl<>(); + } +} diff --git a/approximations/src/main/java/generated/ch/qos/logback/classic/LoggerImpl.java b/approximations/src/main/java/generated/ch/qos/logback/classic/LoggerImpl.java new file mode 100644 index 00000000..caf8f6e8 --- /dev/null +++ b/approximations/src/main/java/generated/ch/qos/logback/classic/LoggerImpl.java @@ -0,0 +1,215 @@ +package generated.ch.qos.logback.classic; + +import ch.qos.logback.classic.Level; +import org.jacodb.approximation.annotation.Approximate; +import org.slf4j.Marker; + +@Approximate(ch.qos.logback.classic.Logger.class) +public class LoggerImpl implements org.slf4j.Logger { + + private transient Level level = Level.OFF; + private transient int effectiveLevelInt = Integer.MAX_VALUE; + + public String getName() { + return ""; + } + + int getEffectiveLevelInt() { + return Integer.MAX_VALUE; + } + + public Level getLevel() { + return Level.OFF; + } + + public boolean isTraceEnabled() { + return false; + } + + public void trace(String s) { + } + + public void trace(String s, Object o) { + } + + public void trace(String s, Object o, Object o1) { + } + + public void trace(String s, Object... objects) { + } + + public void trace(String s, Throwable throwable) { + } + + public boolean isTraceEnabled(Marker marker) { + return false; + } + + public void trace(Marker marker, String s) { + } + + public void trace(Marker marker, String s, Object o) { + } + + public void trace(Marker marker, String s, Object o, Object o1) { + } + + public void trace(Marker marker, String s, Object... objects) { + } + + public void trace(Marker marker, String s, Throwable throwable) { + } + + public boolean isDebugEnabled() { + return false; + } + + public void debug(String s) { + } + + public void debug(String s, Object o) { + } + + public void debug(String s, Object o, Object o1) { + } + + public void debug(String s, Object... objects) { + } + + public void debug(String s, Throwable throwable) { + } + + public boolean isDebugEnabled(Marker marker) { + return false; + } + + public void debug(Marker marker, String s) { + } + + public void debug(Marker marker, String s, Object o) { + } + + public void debug(Marker marker, String s, Object o, Object o1) { + } + + public void debug(Marker marker, String s, Object... objects) { + } + + public void debug(Marker marker, String s, Throwable throwable) { + } + + public boolean isInfoEnabled() { + return false; + } + + public void info(String s) { + } + + public void info(String s, Object o) { + } + + public void info(String s, Object o, Object o1) { + } + + public void info(String s, Object... objects) { + } + + public void info(String s, Throwable throwable) { + } + + public boolean isInfoEnabled(Marker marker) { + return false; + } + + public void info(Marker marker, String s) { + } + + public void info(Marker marker, String s, Object o) { + } + + public void info(Marker marker, String s, Object o, Object o1) { + } + + public void info(Marker marker, String s, Object... objects) { + } + + public void info(Marker marker, String s, Throwable throwable) { + } + + public boolean isWarnEnabled() { + return false; + } + + public void warn(String s) { + } + + public void warn(String s, Object o) { + } + + public void warn(String s, Object... objects) { + } + + public void warn(String s, Object o, Object o1) { + } + + public void warn(String s, Throwable throwable) { + + } + + public boolean isWarnEnabled(Marker marker) { + return false; + } + + public void warn(Marker marker, String s) { + } + + public void warn(Marker marker, String s, Object o) { + } + + public void warn(Marker marker, String s, Object o, Object o1) { + } + + public void warn(Marker marker, String s, Object... objects) { + } + + public void warn(Marker marker, String s, Throwable throwable) { + } + + public boolean isErrorEnabled() { + return false; + } + + public void error(String s) { + } + + public void error(String s, Object o) { + } + + public void error(String s, Object o, Object o1) { + } + + public void error(String s, Object... objects) { + } + + public void error(String s, Throwable throwable) { + } + + public boolean isErrorEnabled(Marker marker) { + return false; + } + + public void error(Marker marker, String s) { + } + + public void error(Marker marker, String s, Object o) { + } + + public void error(Marker marker, String s, Object o, Object o1) { + } + + public void error(Marker marker, String s, Object... objects) { + } + + public void error(Marker marker, String s, Throwable throwable) { + } +} diff --git a/approximations/src/main/java/generated/java/lang/AutoCloseable.java b/approximations/src/main/java/generated/java/lang/AutoCloseable.java index 2454d0b1..f82dcfb3 100644 --- a/approximations/src/main/java/generated/java/lang/AutoCloseable.java +++ b/approximations/src/main/java/generated/java/lang/AutoCloseable.java @@ -1,42 +1,10 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/lang/AutoCloseable.lsl:26 -// - java/lang/AutoCloseable.main.lsl:16 -// package generated.java.lang; -import java.lang.Class; -import java.lang.SuppressWarnings; -import java.lang.Void; import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; -/** - * AutoCloseableAutomaton for LSLAutoCloseable ~> java.lang.AutoCloseable - */ -@SuppressWarnings({"all", "unchecked"}) +@SuppressWarnings("unused") @Approximate(java.lang.AutoCloseable.class) -public interface AutoCloseable extends LibSLRuntime.Automaton { - Class __$_lsl_INIT_INTERFACE_AutoCloseableAutomaton_d61c3b46 = Void.class; +public interface AutoCloseable { - /** - * [FUNCTION] AutoCloseableAutomaton::close(LSLAutoCloseable) -> void - * Source: java/lang/AutoCloseable.main.lsl:39 - */ - default void close() { - /* body */ { - } - } - - final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(AutoCloseable.class) - final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } + default void close() { } } diff --git a/approximations/src/main/java/generated/java/lang/Character.java b/approximations/src/main/java/generated/java/lang/CharacterImpl.java similarity index 59% rename from approximations/src/main/java/generated/java/lang/Character.java rename to approximations/src/main/java/generated/java/lang/CharacterImpl.java index 9139f17c..35492621 100644 --- a/approximations/src/main/java/generated/java/lang/Character.java +++ b/approximations/src/main/java/generated/java/lang/CharacterImpl.java @@ -1,33 +1,22 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/lang/Character.lsl:62 -// - java/lang/Character.patch.lsl:17 -// package generated.java.lang; +import java.io.Serial; import java.io.Serializable; -import java.lang.Class; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; + import org.jacodb.approximation.annotation.Approximate; import org.usvm.api.Engine; -import runtime.LibSLRuntime; -/** - * CharacterAutomaton for LSLCharacter ~> java.lang.Character - */ -@SuppressWarnings({"all", "unchecked"}) +@SuppressWarnings("unused") @Approximate(java.lang.Character.class) -public final class Character implements LibSLRuntime.Automaton, Serializable { +public final class CharacterImpl implements Serializable { + + @Serial private static final long serialVersionUID = 3786198910865385080L; public static final int BYTES = 2; public static final int SIZE = 16; - public static final Class TYPE = java.lang.Character.class; - public static final byte COMBINING_SPACING_MARK = 8; public static final byte CONNECTOR_PUNCTUATION = 23; @@ -176,110 +165,33 @@ public final class Character implements LibSLRuntime.Automaton, Serializable { public char value; - @LibSLRuntime.AutomatonConstructor - public Character(Void __$lsl_token, final byte p0, final char p1) { - this.value = p1; - } - - @LibSLRuntime.AutomatonConstructor - public Character(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, '?'); - } - - /** - * [CONSTRUCTOR] CharacterAutomaton::(LSLCharacter, char) -> void - * Source: java/lang/Character.patch.lsl:47 - */ - public Character(char c) { - this((Void) null); - /* body */ { - this.value = c; - } + public CharacterImpl(char value) { + this.value = value; } - /** - * [FUNCTION] CharacterAutomaton::isWhitespace(char) -> boolean - * Source: java/lang/Character.patch.lsl:55 - */ public static boolean isWhitespace(char ch) { - boolean result = false; - /* body */ { - if ((ch == ' ') || (ch == CHAR_SN) || (ch == CHAR_ST) || (ch == CHAR_SF) || (ch == CHAR_SR)) { - result = true; - } else { - result = false; - } - } - return result; + return ch == ' ' || ch == CHAR_SN || ch == CHAR_ST || ch == CHAR_SF || ch == CHAR_SR; } - /** - * [FUNCTION] CharacterAutomaton::toLowerCase(char) -> char - * Source: java/lang/Character.patch.lsl:65 - */ public static char toLowerCase(char ch) { - char result = '?'; - /* body */ { - if ((ch >= 'A') && (ch <= 'Z')) { - result = ((char) ((ch - 'A') + 'a')); - } else { - result = ch; - } - } - return result; - } + if (ch >= 'A' && ch <= 'Z') + return (char) (ch - 'A' + 'a'); - /** - * [FUNCTION] CharacterAutomaton::toUpperCase(char) -> char - * Source: java/lang/Character.patch.lsl:74 - */ - public static char toUpperCase(char ch) { - char result = '?'; - /* body */ { - if ((ch >= 'a') && (ch <= 'z')) { - result = ((char) ((ch - 'a') + 'A')); - } else { - result = ch; - } - } - return result; + return ch; } - /** - * [FUNCTION] CharacterAutomaton::valueOf(char) -> Character - * Source: java/lang/Character.patch.lsl:83 - */ - public static java.lang.Character valueOf(char c) { - java.lang.Character result = null; - /* body */ { - result = (java.lang.Character) ((Object) new Character((Void) null, - /* state = */ Character.__$lsl_States.Initialized, - /* value = */ c - )); - } - return result; - } + public static char toUpperCase(char ch) { + if (ch >= 'a' && ch <= 'z') + return (char) (ch - 'a' + 'A'); - /** - * [FUNCTION] CharacterAutomaton::charValue(LSLCharacter) -> char - * Source: java/lang/Character.patch.lsl:93 - */ - public char charValue() { - char result = '?'; - /* body */ { - result = this.value; - } - return result; + return ch; } - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; + public static CharacterImpl valueOf(char c) { + return new CharacterImpl(c); } - @Approximate(Character.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } + public char charValue() { + return this.value; } } diff --git a/approximations/src/main/java/generated/java/lang/Double.java b/approximations/src/main/java/generated/java/lang/Double.java deleted file mode 100644 index 754164f4..00000000 --- a/approximations/src/main/java/generated/java/lang/Double.java +++ /dev/null @@ -1,615 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/lang/Double.lsl:35 -// - java/lang/Double.main.lsl:19 -// -package generated.java.lang; - -import java.lang.Class; -import java.lang.Comparable; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * DoubleAutomaton for LSLDouble ~> java.lang.Double - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.lang.Double.class) -public final class Double implements LibSLRuntime.Automaton, Comparable { - private static final long serialVersionUID = -9172774392245257468L; - - public static final int BYTES = 8; - - public static final int SIZE = 64; - - public static final int MAX_EXPONENT = 1023; - - public static final int MIN_EXPONENT = -1022; - - public static final double MAX_VALUE = 1.7976931348623157E308d; - - public static final double MIN_VALUE = 4.9E-324d; - - public static final double MIN_NORMAL = 2.2250738585072014E-308d; - - public static final double POSITIVE_INFINITY = 1.0d / 0.0d; - - public static final double NEGATIVE_INFINITY = -1.0d / 0.0d; - - public static final double NaN = 0.0d / 0.0d; - - public static final Class TYPE = java.lang.Double.class; - - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public double value; - - @LibSLRuntime.AutomatonConstructor - public Double(Void __$lsl_token, final byte p0, final double p1) { - this.__$lsl_state = p0; - this.value = p1; - } - - @LibSLRuntime.AutomatonConstructor - public Double(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, 0.0d); - } - - /** - * [CONSTRUCTOR] DoubleAutomaton::(LSLDouble, double) -> void - * Source: java/lang/Double.main.lsl:125 - */ - public Double(double v) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.value = v; - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] DoubleAutomaton::_getRawBits(double) -> long - * Source: java/lang/Double.main.lsl:74 - */ - private static long _getRawBits(double v) { - long result = 0L; - /* body */ { - if (v != v) { - result = 9221120237041090560L; - } else { - if ((1.0d / v) == NEGATIVE_INFINITY) { - result = -9223372036854775808L; - } else { - if (v == 0.0d) { - result = 0L; - } else { - if (v == POSITIVE_INFINITY) { - result = 9218868437227405312L; - } else { - if (v == NEGATIVE_INFINITY) { - result = -4503599627370496L; - } else { - result = Engine.makeSymbolicLong(); - Engine.assume(result != 9221120237041090560L); - Engine.assume(result != -9223372036854775808L); - Engine.assume(result != 0L); - Engine.assume(result != 9218868437227405312L); - Engine.assume(result != -4503599627370496L); - if (v < 0.0d) { - Engine.assume(result < 0L); - } else { - Engine.assume(result > 0L); - } - } - } - } - } - } - } - return result; - } - - /** - * [SUBROUTINE] DoubleAutomaton::_parse(String) -> double - * Source: java/lang/Double.main.lsl:105 - */ - private static double _parse(String str) throws java.lang.NumberFormatException { - double result = 0.0d; - /* body */ { - if (str == null) { - throw new NullPointerException(); - } - LibSLRuntime.todo(); - } - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::compare(double, double) -> int - * Source: java/lang/Double.main.lsl:133 - */ - public static int compare(double a, double b) { - int result = 0; - // WARNING: no state checks in static context - /* body */ { - if ((a == b) || (a != a) || (b != b)) { - result = 0; - } else { - if (a < b) { - result = -1; - } else { - result = 1; - } - } - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::doubleToLongBits(double) -> long - * Source: java/lang/Double.main.lsl:150 - */ - public static long doubleToLongBits(double value) { - long result = 0L; - // WARNING: no state checks in static context - /* body */ { - result = _getRawBits(value); - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::doubleToRawLongBits(double) -> long - * Source: java/lang/Double.main.lsl:156 - */ - public static long doubleToRawLongBits(double value) { - long result = 0L; - // WARNING: no state checks in static context - /* body */ { - result = _getRawBits(value); - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::hashCode(double) -> int - * Source: java/lang/Double.main.lsl:162 - */ - public static int hashCode(double value) { - int result = 0; - // WARNING: no state checks in static context - /* body */ { - result = ((int) _getRawBits(value)); - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::isFinite(double) -> boolean - * Source: java/lang/Double.main.lsl:168 - */ - public static boolean isFinite(double d) { - boolean result = false; - // WARNING: no state checks in static context - /* body */ { - if (d <= 0.0d) { - d = 0.0d - d; - } - result = d <= MAX_VALUE; - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::isInfinite(double) -> boolean - * Source: java/lang/Double.main.lsl:178 - */ - public static boolean isInfinite(double v) { - boolean result = false; - // WARNING: no state checks in static context - /* body */ { - result = (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY); - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::isNaN(double) -> boolean - * Source: java/lang/Double.main.lsl:185 - */ - public static boolean isNaN(double v) { - boolean result = false; - // WARNING: no state checks in static context - /* body */ { - result = v != v; - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::longBitsToDouble(long) -> double - * Source: java/lang/Double.main.lsl:191 - */ - public static double longBitsToDouble(long value) { - double result = 0.0d; - // WARNING: no state checks in static context - /* body */ { - if (value == 9221120237041090560L) { - result = NaN; - } else { - if (value == -9223372036854775808L) { - result = -0.0d; - } else { - if (value == 0L) { - result = 0.0d; - } else { - if (value == 9218868437227405312L) { - result = POSITIVE_INFINITY; - } else { - if (value == -4503599627370496L) { - result = NEGATIVE_INFINITY; - } else { - result = Engine.makeSymbolicDouble(); - Engine.assume(result != 0.0d); - Engine.assume(result == result); - Engine.assume(result != POSITIVE_INFINITY); - Engine.assume(result != NEGATIVE_INFINITY); - if (value < 0L) { - Engine.assume(result < 0.0d); - } else { - Engine.assume(result > 0.0d); - } - } - } - } - } - } - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::max(double, double) -> double - * Source: java/lang/Double.main.lsl:221 - */ - public static double max(double a, double b) { - double result = 0.0d; - // WARNING: no state checks in static context - /* body */ { - if (a != a) { - result = a; - } else { - if ((a == 0.0d) && (b == 0.0d) && ((1.0d / a) == NEGATIVE_INFINITY)) { - result = b; - } else { - if (a >= b) { - result = a; - } else { - result = b; - } - } - } - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::min(double, double) -> double - * Source: java/lang/Double.main.lsl:234 - */ - public static double min(double a, double b) { - double result = 0.0d; - // WARNING: no state checks in static context - /* body */ { - if (a != a) { - result = a; - } else { - if ((a == 0.0d) && (b == 0.0d) && ((1.0d / b) == NEGATIVE_INFINITY)) { - result = b; - } else { - if (a <= b) { - result = a; - } else { - result = b; - } - } - } - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::sum(double, double) -> double - * Source: java/lang/Double.main.lsl:255 - */ - public static double sum(double a, double b) { - double result = 0.0d; - // WARNING: no state checks in static context - /* body */ { - result = a + b; - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::toHexString(double) -> String - * Source: java/lang/Double.main.lsl:261 - */ - public static String toHexString(double d) { - String result = null; - // WARNING: no state checks in static context - /* body */ { - if (d != d) { - result = "NaN"; - } else { - if (d == POSITIVE_INFINITY) { - result = "Infinity"; - } else { - if (d == NEGATIVE_INFINITY) { - result = "-Infinity"; - } else { - if ((1.0d / d) == NEGATIVE_INFINITY) { - result = "-0x0.0p0"; - } else { - if (d == 0.0f) { - result = "0x0.0p0"; - } else { - if (d == 1.0f) { - result = "0x1.0p0"; - } else { - if (d == -1.0f) { - result = "-0x1.0p0"; - } else { - result = Engine.makeSymbolic(String.class); - Engine.assume(result != null); - final int len = result.length(); - Engine.assume(len >= 7); - Engine.assume(len <= 22); - } - } - } - } - } - } - } - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::toString(double) -> String - * Source: java/lang/Double.main.lsl:282 - */ - public static String toString(double d) { - String result = null; - // WARNING: no state checks in static context - /* body */ { - result = LibSLRuntime.toString(d); - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::valueOf(double) -> Double - * Source: java/lang/Double.main.lsl:298 - */ - public static java.lang.Double valueOf(double d) { - java.lang.Double result = null; - // WARNING: no state checks in static context - /* body */ { - result = (java.lang.Double) ((Object) new Double((Void) null, - /* state = */ Double.__$lsl_States.Initialized, - /* value = */ d - )); - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::byteValue(LSLDouble) -> byte - * Source: java/lang/Double.main.lsl:308 - */ - public byte byteValue() { - byte result = ((byte) 0); - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((byte) this.value); - } - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::compareTo(LSLDouble, LSLDouble) -> int - * Source: java/lang/Double.main.lsl:314 - */ - public int compareTo(Double anotherDouble) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final double a = this.value; - final double b = ((Double) ((Object) anotherDouble)).value; - if ((a == b) || (a != a) || (b != b)) { - result = 0; - } else { - if (a < b) { - result = -1; - } else { - result = 1; - } - } - } - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::doubleValue(LSLDouble) -> double - * Source: java/lang/Double.main.lsl:334 - */ - public double doubleValue() { - double result = 0.0d; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - } - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::equals(LSLDouble, Object) -> boolean - * Source: java/lang/Double.main.lsl:340 - */ - public boolean equals(Object obj) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if ((obj instanceof java.lang.Double)) { - result = this.value == ((Double) ((Object) obj)).value; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::floatValue(LSLDouble) -> float - * Source: java/lang/Double.main.lsl:349 - */ - public float floatValue() { - float result = 0.0f; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((float) this.value); - } - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::hashCode(LSLDouble) -> int - * Source: java/lang/Double.main.lsl:355 - */ - public int hashCode() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((int) _getRawBits(this.value)); - } - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::intValue(LSLDouble) -> int - * Source: java/lang/Double.main.lsl:361 - */ - public int intValue() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((int) this.value); - } - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::isInfinite(LSLDouble) -> boolean - * Source: java/lang/Double.main.lsl:367 - */ - public boolean isInfinite() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (this.value == POSITIVE_INFINITY) || (this.value == NEGATIVE_INFINITY); - } - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::isNaN(LSLDouble) -> boolean - * Source: java/lang/Double.main.lsl:374 - */ - public boolean isNaN() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value != this.value; - } - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::longValue(LSLDouble) -> long - * Source: java/lang/Double.main.lsl:380 - */ - public long longValue() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((long) this.value); - } - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::shortValue(LSLDouble) -> short - * Source: java/lang/Double.main.lsl:386 - */ - public short shortValue() { - short result = ((short) 0); - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((short) this.value); - } - return result; - } - - /** - * [FUNCTION] DoubleAutomaton::toString(LSLDouble) -> String - * Source: java/lang/Double.main.lsl:392 - */ - public String toString() { - String result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = LibSLRuntime.toString(this.value); - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(Double.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/lang/DoubleImpl.java b/approximations/src/main/java/generated/java/lang/DoubleImpl.java new file mode 100644 index 00000000..e02e9acd --- /dev/null +++ b/approximations/src/main/java/generated/java/lang/DoubleImpl.java @@ -0,0 +1,285 @@ +package generated.java.lang; + +import java.io.Serial; +import java.io.Serializable; +import java.lang.Comparable; +import java.lang.NullPointerException; +import java.lang.Object; +import java.lang.String; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +@SuppressWarnings("unused") +@Approximate(java.lang.Double.class) +public final class DoubleImpl implements Comparable, Serializable { + + @Serial + private static final long serialVersionUID = -9172774392245257468L; + + public static final int BYTES = 8; + + public static final int SIZE = 64; + + public static final int MAX_EXPONENT = 1023; + + public static final int MIN_EXPONENT = -1022; + + public static final double MAX_VALUE = 1.7976931348623157E308d; + + public static final double MIN_VALUE = 4.9E-324d; + + public static final double MIN_NORMAL = 2.2250738585072014E-308d; + + @SuppressWarnings({"divzero", "NumericOverflow"}) + public static final double POSITIVE_INFINITY = 1.0d / 0.0d; + + @SuppressWarnings({"divzero", "NumericOverflow"}) + public static final double NEGATIVE_INFINITY = -1.0d / 0.0d; + + @SuppressWarnings("divzero") + public static final double NaN = 0.0d / 0.0d; + + static { + Engine.assume(true); + } + + public double value; + + public DoubleImpl(double value) { + this.value = value; + } + + private static boolean _isNan(double d) { + return d != d; + } + + private static long _getRawBits(double v) { + if (_isNan(v)) + return 9221120237041090560L; + + if (1.0d / v == NEGATIVE_INFINITY) + return -9223372036854775808L; + + if (v == 0.0d) + return 0L; + + if (v == POSITIVE_INFINITY) + return 9218868437227405312L; + + if (v == NEGATIVE_INFINITY) + return -4503599627370496L; + + long result = Engine.makeSymbolicLong(); + Engine.assume(result != 9221120237041090560L); + Engine.assume(result != -9223372036854775808L); + Engine.assume(result != 0L); + Engine.assume(result != 9218868437227405312L); + Engine.assume(result != -4503599627370496L); + if (v < 0.0d) { + Engine.assume(result < 0L); + } else { + Engine.assume(result > 0L); + } + + return result; + } + + private static double _parse(String str) throws java.lang.NumberFormatException { + if (str == null) { + throw new NullPointerException(); + } + + LibSLRuntime.todo(); + return 0.0d; + } + + public static int compare(double a, double b) { + if (a == b || _isNan(a) || _isNan(b)) + return 0; + + if (a < b) + return -1; + + return 1; + } + + public static long doubleToLongBits(double value) { + return _getRawBits(value); + } + + public static long doubleToRawLongBits(double value) { + return _getRawBits(value); + } + + public static int hashCode(double value) { + return (int) _getRawBits(value); + } + + public static boolean isFinite(double d) { + if (d <= 0.0d) + d = 0.0d - d; + return d <= MAX_VALUE; + } + + public static boolean isInfinite(double v) { + return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY); + } + + public static boolean isNaN(double v) { + return _isNan(v); + } + + public static double longBitsToDouble(long value) { + if (value == 9221120237041090560L) + return NaN; + + if (value == -9223372036854775808L) + return -0.0d; + + if (value == 0L) + return 0.0d; + + if (value == 9218868437227405312L) + return POSITIVE_INFINITY; + + if (value == -4503599627370496L) + return NEGATIVE_INFINITY; + + double result = Engine.makeSymbolicDouble(); + Engine.assume(result != 0.0d); + Engine.assume(result == result); + Engine.assume(result != POSITIVE_INFINITY); + Engine.assume(result != NEGATIVE_INFINITY); + if (value < 0L) { + Engine.assume(result < 0.0d); + } else { + Engine.assume(result > 0.0d); + } + return result; + } + + @SuppressWarnings("ManualMinMaxCalculation") + public static double max(double a, double b) { + if (_isNan(a)) + return a; + + if (a == 0.0d && b == 0.0d && (1.0d / a) == NEGATIVE_INFINITY) + return b; + + if (a >= b) + return a; + + return b; + } + + @SuppressWarnings("ManualMinMaxCalculation") + public static double min(double a, double b) { + if (_isNan(a)) + return a; + + if (a == 0.0d && b == 0.0d && (1.0d / b) == NEGATIVE_INFINITY) + return b; + + if (a <= b) + return a; + + return b; + } + + public static double sum(double a, double b) { + return a + b; + } + + @SuppressWarnings({"ConstantValue", "DataFlowIssue"}) + public static String toHexString(double d) { + if (_isNan(d)) + return "NaN"; + + if (d == POSITIVE_INFINITY) + return "Infinity"; + + if (d == NEGATIVE_INFINITY) + return "-Infinity"; + + if ((1.0d / d) == NEGATIVE_INFINITY) + return "-0x0.0p0"; + + if (d == 0.0f) + return "0x0.0p0"; + + if (d == 1.0f) + return "0x1.0p0"; + + if (d == -1.0f) + return "-0x1.0p0"; + + String result = Engine.makeSymbolic(String.class); + Engine.assume(result != null); + int len = result.length(); + Engine.assume(len >= 7); + Engine.assume(len <= 22); + return result; + } + + public static String toString(double d) { + return LibSLRuntime.toString(d); + } + + public static DoubleImpl valueOf(double d) { + return new DoubleImpl(d); + } + + public byte byteValue() { + return (byte) this.value; + } + + public int compareTo(DoubleImpl anotherDoubleImpl) { + return compare(this.value, anotherDoubleImpl.value); + } + + public double doubleValue() { + return this.value; + } + + @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") + public boolean equals(Object obj) { + if (Engine.typeIs(obj, DoubleImpl.class)) + return this.value == ((DoubleImpl) obj).value; + + return false; + } + + public float floatValue() { + return (float) this.value; + } + + public int hashCode() { + return (int) _getRawBits(this.value); + } + + public int intValue() { + return (int) this.value; + } + + public boolean isInfinite() { + return isInfinite(this.value); + } + + public boolean isNaN() { + return isNaN(this.value); + } + + public long longValue() { + return (long) this.value; + } + + public short shortValue() { + return (short) this.value; + } + + public String toString() { + return LibSLRuntime.toString(this.value); + } +} diff --git a/approximations/src/main/java/generated/java/lang/Float.java b/approximations/src/main/java/generated/java/lang/Float.java deleted file mode 100644 index a91df9f6..00000000 --- a/approximations/src/main/java/generated/java/lang/Float.java +++ /dev/null @@ -1,628 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/lang/Float.lsl:35 -// - java/lang/Float.main.lsl:18 -// -package generated.java.lang; - -import java.lang.Class; -import java.lang.Comparable; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * FloatAutomaton for LSLFloat ~> java.lang.Float - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.lang.Float.class) -public final class Float implements LibSLRuntime.Automaton, Comparable { - private static final long serialVersionUID = -2671257302660747028L; - - public static final int BYTES = 4; - - public static final int SIZE = 32; - - public static final int MAX_EXPONENT = 127; - - public static final int MIN_EXPONENT = -126; - - public static final float MAX_VALUE = 3.4028235E38f; - - public static final float MIN_VALUE = 1.4E-45f; - - public static final float MIN_NORMAL = 1.17549435E-38f; - - public static final float NEGATIVE_INFINITY = -1.0f / 0.0f; - - public static final float POSITIVE_INFINITY = 1.0f / 0.0f; - - public static final float NaN = 0.0f / 0.0f; - - public static final Class TYPE = java.lang.Float.class; - - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public float value; - - @LibSLRuntime.AutomatonConstructor - public Float(Void __$lsl_token, final byte p0, final float p1) { - this.__$lsl_state = p0; - this.value = p1; - } - - @LibSLRuntime.AutomatonConstructor - public Float(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, 0.0f); - } - - /** - * [CONSTRUCTOR] FloatAutomaton::(LSLFloat, double) -> void - * Source: java/lang/Float.main.lsl:126 - */ - public Float(double v) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.value = ((float) v); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] FloatAutomaton::(LSLFloat, float) -> void - * Source: java/lang/Float.main.lsl:132 - */ - public Float(float v) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.value = v; - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] FloatAutomaton::_getRawBits(float) -> int - * Source: java/lang/Float.main.lsl:74 - */ - private static int _getRawBits(float v) { - int result = 0; - /* body */ { - if (v != v) { - result = 2143289344; - } else { - if ((1.0f / v) == NEGATIVE_INFINITY) { - result = -2147483648; - } else { - if (v == 0.0f) { - result = 0; - } else { - if (v == POSITIVE_INFINITY) { - result = 2139095040; - } else { - if (v == NEGATIVE_INFINITY) { - result = -8388608; - } else { - result = Engine.makeSymbolicInt(); - Engine.assume(result != 2143289344); - Engine.assume(result != -2147483648); - Engine.assume(result != 0); - Engine.assume(result != 2139095040); - Engine.assume(result != -8388608); - if (v < 0.0f) { - Engine.assume(result < 0); - } else { - Engine.assume(result > 0); - } - } - } - } - } - } - } - return result; - } - - /** - * [SUBROUTINE] FloatAutomaton::_parse(String) -> float - * Source: java/lang/Float.main.lsl:105 - */ - private static float _parse(String str) throws java.lang.NumberFormatException { - float result = 0.0f; - /* body */ { - if (str == null) { - throw new NullPointerException(); - } - LibSLRuntime.todo(); - } - return result; - } - - /** - * [FUNCTION] FloatAutomaton::compare(float, float) -> int - * Source: java/lang/Float.main.lsl:140 - */ - public static int compare(float a, float b) { - int result = 0; - // WARNING: no state checks in static context - /* body */ { - if ((a == b) || (a != a) || (b != b)) { - result = 0; - } else { - if (a < b) { - result = -1; - } else { - result = 1; - } - } - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] FloatAutomaton::floatToIntBits(float) -> int - * Source: java/lang/Float.main.lsl:157 - */ - public static int floatToIntBits(float value) { - int result = 0; - // WARNING: no state checks in static context - /* body */ { - result = _getRawBits(value); - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] FloatAutomaton::floatToRawIntBits(float) -> int - * Source: java/lang/Float.main.lsl:163 - */ - public static int floatToRawIntBits(float value) { - int result = 0; - // WARNING: no state checks in static context - /* body */ { - result = _getRawBits(value); - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] FloatAutomaton::hashCode(float) -> int - * Source: java/lang/Float.main.lsl:169 - */ - public static int hashCode(float value) { - int result = 0; - // WARNING: no state checks in static context - /* body */ { - result = _getRawBits(value); - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] FloatAutomaton::intBitsToFloat(int) -> float - * Source: java/lang/Float.main.lsl:175 - */ - public static float intBitsToFloat(int value) { - float result = 0.0f; - // WARNING: no state checks in static context - /* body */ { - if (value == 2143289344) { - result = NaN; - } else { - if (value == -2147483648) { - result = -0.0f; - } else { - if (value == 0) { - result = 0.0f; - } else { - if (value == 2139095040) { - result = POSITIVE_INFINITY; - } else { - if (value == -8388608) { - result = NEGATIVE_INFINITY; - } else { - result = Engine.makeSymbolicFloat(); - Engine.assume(result != 0.0f); - Engine.assume(result == result); - Engine.assume(result != POSITIVE_INFINITY); - Engine.assume(result != NEGATIVE_INFINITY); - if (value < 0) { - Engine.assume(result < 0.0f); - } else { - Engine.assume(result > 0.0f); - } - } - } - } - } - } - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] FloatAutomaton::isFinite(float) -> boolean - * Source: java/lang/Float.main.lsl:205 - */ - public static boolean isFinite(float f) { - boolean result = false; - // WARNING: no state checks in static context - /* body */ { - if (f <= 0.0f) { - f = 0.0f - f; - } - result = f <= MAX_VALUE; - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] FloatAutomaton::isInfinite(float) -> boolean - * Source: java/lang/Float.main.lsl:215 - */ - public static boolean isInfinite(float v) { - boolean result = false; - // WARNING: no state checks in static context - /* body */ { - result = (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY); - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] FloatAutomaton::isNaN(float) -> boolean - * Source: java/lang/Float.main.lsl:222 - */ - public static boolean isNaN(float v) { - boolean result = false; - // WARNING: no state checks in static context - /* body */ { - result = v != v; - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] FloatAutomaton::max(float, float) -> float - * Source: java/lang/Float.main.lsl:228 - */ - public static float max(float a, float b) { - float result = 0.0f; - // WARNING: no state checks in static context - /* body */ { - if (a != a) { - result = a; - } else { - if ((a == 0.0f) && (b == 0.0f) && ((1.0f / a) == NEGATIVE_INFINITY)) { - result = b; - } else { - if (a >= b) { - result = a; - } else { - result = b; - } - } - } - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] FloatAutomaton::min(float, float) -> float - * Source: java/lang/Float.main.lsl:241 - */ - public static float min(float a, float b) { - float result = 0.0f; - // WARNING: no state checks in static context - /* body */ { - if (a != a) { - result = a; - } else { - if ((a == 0.0f) && (b == 0.0f) && ((1.0f / b) == NEGATIVE_INFINITY)) { - result = b; - } else { - if (a <= b) { - result = a; - } else { - result = b; - } - } - } - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] FloatAutomaton::sum(float, float) -> float - * Source: java/lang/Float.main.lsl:262 - */ - public static float sum(float a, float b) { - float result = 0.0f; - // WARNING: no state checks in static context - /* body */ { - result = a + b; - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] FloatAutomaton::toHexString(float) -> String - * Source: java/lang/Float.main.lsl:268 - */ - public static String toHexString(float f) { - String result = null; - // WARNING: no state checks in static context - /* body */ { - if (f != f) { - result = "NaN"; - } else { - if (f == POSITIVE_INFINITY) { - result = "Infinity"; - } else { - if (f == NEGATIVE_INFINITY) { - result = "-Infinity"; - } else { - if ((1.0f / f) == NEGATIVE_INFINITY) { - result = "-0x0.0p0"; - } else { - if (f == 0.0f) { - result = "0x0.0p0"; - } else { - if (f == 1.0f) { - result = "0x1.0p0"; - } else { - if (f == -1.0f) { - result = "-0x1.0p0"; - } else { - result = Engine.makeSymbolic(String.class); - Engine.assume(result != null); - final int len = result.length(); - Engine.assume(len >= 7); - Engine.assume(len <= 14); - } - } - } - } - } - } - } - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] FloatAutomaton::toString(float) -> String - * Source: java/lang/Float.main.lsl:289 - */ - public static String toString(float f) { - String result = null; - // WARNING: no state checks in static context - /* body */ { - result = LibSLRuntime.toString(f); - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] FloatAutomaton::valueOf(float) -> Float - * Source: java/lang/Float.main.lsl:305 - */ - public static java.lang.Float valueOf(float f) { - java.lang.Float result = null; - // WARNING: no state checks in static context - /* body */ { - result = (java.lang.Float) ((Object) new Float((Void) null, - /* state = */ Float.__$lsl_States.Initialized, - /* value = */ f - )); - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] FloatAutomaton::byteValue(LSLFloat) -> byte - * Source: java/lang/Float.main.lsl:315 - */ - public byte byteValue() { - byte result = ((byte) 0); - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((byte) this.value); - } - return result; - } - - /** - * [FUNCTION] FloatAutomaton::compareTo(LSLFloat, LSLFloat) -> int - * Source: java/lang/Float.main.lsl:321 - */ - public int compareTo(Float anotherFloat) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final float a = this.value; - final float b = ((Float) ((Object) anotherFloat)).value; - if ((a == b) || (a != a) || (b != b)) { - result = 0; - } else { - if (a < b) { - result = -1; - } else { - result = 1; - } - } - } - return result; - } - - /** - * [FUNCTION] FloatAutomaton::doubleValue(LSLFloat) -> double - * Source: java/lang/Float.main.lsl:341 - */ - public double doubleValue() { - double result = 0.0d; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((double) this.value); - } - return result; - } - - /** - * [FUNCTION] FloatAutomaton::equals(LSLFloat, Object) -> boolean - * Source: java/lang/Float.main.lsl:347 - */ - public boolean equals(Object obj) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if ((obj instanceof java.lang.Float)) { - result = this.value == ((Float) ((Object) obj)).value; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] FloatAutomaton::floatValue(LSLFloat) -> float - * Source: java/lang/Float.main.lsl:356 - */ - public float floatValue() { - float result = 0.0f; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - } - return result; - } - - /** - * [FUNCTION] FloatAutomaton::hashCode(LSLFloat) -> int - * Source: java/lang/Float.main.lsl:362 - */ - public int hashCode() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _getRawBits(this.value); - } - return result; - } - - /** - * [FUNCTION] FloatAutomaton::intValue(LSLFloat) -> int - * Source: java/lang/Float.main.lsl:368 - */ - public int intValue() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((int) this.value); - } - return result; - } - - /** - * [FUNCTION] FloatAutomaton::isInfinite(LSLFloat) -> boolean - * Source: java/lang/Float.main.lsl:374 - */ - public boolean isInfinite() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (this.value == POSITIVE_INFINITY) || (this.value == NEGATIVE_INFINITY); - } - return result; - } - - /** - * [FUNCTION] FloatAutomaton::isNaN(LSLFloat) -> boolean - * Source: java/lang/Float.main.lsl:381 - */ - public boolean isNaN() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value != this.value; - } - return result; - } - - /** - * [FUNCTION] FloatAutomaton::longValue(LSLFloat) -> long - * Source: java/lang/Float.main.lsl:387 - */ - public long longValue() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((long) this.value); - } - return result; - } - - /** - * [FUNCTION] FloatAutomaton::shortValue(LSLFloat) -> short - * Source: java/lang/Float.main.lsl:393 - */ - public short shortValue() { - short result = ((short) 0); - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((short) this.value); - } - return result; - } - - /** - * [FUNCTION] FloatAutomaton::toString(LSLFloat) -> String - * Source: java/lang/Float.main.lsl:399 - */ - public String toString() { - String result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = LibSLRuntime.toString(this.value); - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(Float.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/lang/FloatImpl.java b/approximations/src/main/java/generated/java/lang/FloatImpl.java new file mode 100644 index 00000000..4e39306c --- /dev/null +++ b/approximations/src/main/java/generated/java/lang/FloatImpl.java @@ -0,0 +1,289 @@ +package generated.java.lang; + +import java.io.Serial; +import java.io.Serializable; +import java.lang.Comparable; +import java.lang.NullPointerException; +import java.lang.Object; +import java.lang.String; +import java.lang.SuppressWarnings; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +@SuppressWarnings("unused") +@Approximate(java.lang.Float.class) +public final class FloatImpl implements Comparable, Serializable { + + @Serial + private static final long serialVersionUID = -2671257302660747028L; + + public static final int BYTES = 4; + + public static final int SIZE = 32; + + public static final int MAX_EXPONENT = 127; + + public static final int MIN_EXPONENT = -126; + + public static final float MAX_VALUE = 3.4028235E38f; + + public static final float MIN_VALUE = 1.4E-45f; + + public static final float MIN_NORMAL = 1.17549435E-38f; + + @SuppressWarnings({"NumericOverflow", "divzero"}) + public static final float NEGATIVE_INFINITY = -1.0f / 0.0f; + + @SuppressWarnings({"divzero", "NumericOverflow"}) + public static final float POSITIVE_INFINITY = 1.0f / 0.0f; + + @SuppressWarnings("divzero") + public static final float NaN = 0.0f / 0.0f; + + static { + Engine.assume(true); + } + + public float value; + + public FloatImpl(float value) { + this.value = value; + } + + public FloatImpl(double v) { + this.value = ((float) v); + } + + private static boolean _isNan(float f) { + return f != f; + } + + private static int _getRawBits(float v) { + if (_isNan(v)) + return 2143289344; + + if (1.0f / v == NEGATIVE_INFINITY) + return -2147483648; + + if (v == 0.0f) + return 0; + + if (v == POSITIVE_INFINITY) + return 2139095040; + + if (v == NEGATIVE_INFINITY) + return -8388608; + + int result = Engine.makeSymbolicInt(); + Engine.assume(result != 2143289344); + Engine.assume(result != -2147483648); + Engine.assume(result != 0); + Engine.assume(result != 2139095040); + Engine.assume(result != -8388608); + if (v < 0.0f) { + Engine.assume(result < 0); + } else { + Engine.assume(result > 0); + } + return result; + } + + private static float _parse(String str) throws java.lang.NumberFormatException { + if (str == null) { + throw new NullPointerException(); + } + LibSLRuntime.todo(); + return 0.0f; + } + + public static int compare(float a, float b) { + if (a == b || _isNan(a) || _isNan(b)) + return 0; + + if (a < b) + return -1; + + return 1; + } + + public static int floatToIntBits(float value) { + return _getRawBits(value); + } + + public static int floatToRawIntBits(float value) { + return _getRawBits(value); + } + + public static int hashCode(float value) { + return _getRawBits(value); + } + + public static float intBitsToFloat(int value) { + if (value == 2143289344) + return NaN; + + if (value == -2147483648) + return -0.0f; + + if (value == 0) + return 0.0f; + + if (value == 2139095040) + return POSITIVE_INFINITY; + + if (value == -8388608) + return NEGATIVE_INFINITY; + + float result = Engine.makeSymbolicFloat(); + Engine.assume(result != 0.0f); + Engine.assume(result == result); + Engine.assume(result != POSITIVE_INFINITY); + Engine.assume(result != NEGATIVE_INFINITY); + if (value < 0) { + Engine.assume(result < 0.0f); + } else { + Engine.assume(result > 0.0f); + } + return result; + } + + public static boolean isFinite(float f) { + if (f <= 0.0f) + f = 0.0f - f; + + return f <= MAX_VALUE; + } + + public static boolean isInfinite(float v) { + return v == POSITIVE_INFINITY || v == NEGATIVE_INFINITY; + } + + public static boolean isNaN(float v) { + return _isNan(v); + } + + @SuppressWarnings("ManualMinMaxCalculation") + public static float max(float a, float b) { + if (_isNan(a)) + return a; + + if (a == 0.0f && b == 0.0f && (1.0f / a) == NEGATIVE_INFINITY) + return b; + + if (a >= b) + return a; + + return b; + } + + @SuppressWarnings("ManualMinMaxCalculation") + public static float min(float a, float b) { + if (_isNan(a)) + return a; + + if (a == 0.0f && b == 0.0f && (1.0f / b) == NEGATIVE_INFINITY) + return b; + + if (a <= b) + return a; + + return b; + } + + public static float sum(float a, float b) { + return a + b; + } + + @SuppressWarnings({"ConstantValue", "DataFlowIssue"}) + public static String toHexString(float f) { + if (f != f) + return "NaN"; + + if (f == POSITIVE_INFINITY) + return "Infinity"; + + if (f == NEGATIVE_INFINITY) + return "-Infinity"; + + if (1.0f / f == NEGATIVE_INFINITY) + return "-0x0.0p0"; + + if (f == 0.0f) + return "0x0.0p0"; + + if (f == 1.0f) + return "0x1.0p0"; + + if (f == -1.0f) + return "-0x1.0p0"; + + String result = Engine.makeSymbolic(String.class); + Engine.assume(result != null); + int len = result.length(); + Engine.assume(len >= 7); + Engine.assume(len <= 14); + return result; + } + + public static String toString(float f) { + return LibSLRuntime.toString(f); + } + + public static FloatImpl valueOf(float f) { + return new FloatImpl(f); + } + + public byte byteValue() { + return (byte) this.value; + } + + public int compareTo(FloatImpl anotherFloatImpl) { + return compare(this.value, anotherFloatImpl.value); + } + + public double doubleValue() { + return this.value; + } + + @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") + public boolean equals(Object obj) { + if (Engine.typeIs(obj, FloatImpl.class)) + return this.value == ((FloatImpl) obj).value; + + return false; + } + + public float floatValue() { + return this.value; + } + + public int hashCode() { + return _getRawBits(this.value); + } + + public int intValue() { + return (int) this.value; + } + + public boolean isInfinite() { + return isInfinite(this.value); + } + + public boolean isNaN() { + return _isNan(this.value); + } + + public long longValue() { + return (long) this.value; + } + + public short shortValue() { + return (short) this.value; + } + + public String toString() { + return LibSLRuntime.toString(this.value); + } +} diff --git a/approximations/src/main/java/generated/java/lang/Integer.java b/approximations/src/main/java/generated/java/lang/Integer.java deleted file mode 100644 index 01758490..00000000 --- a/approximations/src/main/java/generated/java/lang/Integer.java +++ /dev/null @@ -1,577 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/lang/Integer.lsl:30 -// - java/lang/Integer.main.lsl:20 -// -package generated.java.lang; - -import java.lang.Class; -import java.lang.Comparable; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * IntegerAutomaton for LSLInteger ~> java.lang.Integer - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.lang.Integer.class) -public final class Integer implements LibSLRuntime.Automaton, Comparable { - private static final long serialVersionUID = 1360826667806852920L; - - public static final int MIN_VALUE = -2147483648; - - public static final int MAX_VALUE = 2147483647; - - public static final Class TYPE = java.lang.Integer.class; - - public static final int SIZE = 32; - - public static final int BYTES = 4; - - public static final char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; - - public static final char[] DigitTens = { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '3', '3', '3', '3', '3', '3', '3', '3', '3', '3', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5', '6', '6', '6', '6', '6', '6', '6', '6', '6', '6', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '9', '9', '9', '9', '9', '9', '9', '9', '9', '9' }; - - public static final char[] DigitOnes = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; - - public static final int[] sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, 2147483647 }; - - static { - Engine.assume(true); - } - - private int value; - - @LibSLRuntime.AutomatonConstructor - public Integer(Void __$lsl_token, final byte p0, final int p1) { - this.value = p1; - } - - @LibSLRuntime.AutomatonConstructor - public Integer(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, 0); - } - - /** - * [CONSTRUCTOR] IntegerAutomaton::(LSLInteger, int) -> void - * Source: java/lang/Integer.main.lsl:114 - */ - public Integer(int v) { - this((Void) null); - /* body */ { - this.value = v; - } - } - - /** - * [SUBROUTINE] IntegerAutomaton::_parse(String) -> int - * Source: java/lang/Integer.main.lsl:93 - */ - private static int _parse(String str) throws java.lang.NumberFormatException { - int result = 0; - /* body */ { - if (str == null) { - throw new NullPointerException(); - } - LibSLRuntime.todo(); - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::bitCount(int) -> int - * Source: java/lang/Integer.main.lsl:122 - */ - public static int bitCount(int i) { - int result = 0; - /* body */ { - i = i - ((i >>> 1) & 1431655765); - i = (i & 858993459) + ((i >>> 2) & 858993459); - i = (i + (i >>> 4)) & 252645135; - i = i + (i >>> 8); - i = i + (i >>> 16); - result = i & 63; - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::compare(int, int) -> int - * Source: java/lang/Integer.main.lsl:134 - */ - public static int compare(int x, int y) { - int result = 0; - /* body */ { - if (x == y) { - result = 0; - } else { - if (x < y) { - result = -1; - } else { - result = 1; - } - } - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::compareUnsigned(int, int) -> int - * Source: java/lang/Integer.main.lsl:150 - */ - public static int compareUnsigned(int x, int y) { - int result = 0; - /* body */ { - x += MIN_VALUE; - y += MIN_VALUE; - if (x == y) { - result = 0; - } else { - if (x < y) { - result = -1; - } else { - result = 1; - } - } - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::divideUnsigned(int, int) -> int - * Source: java/lang/Integer.main.lsl:176 - */ - public static int divideUnsigned(int dividend, int divisor) { - int result = 0; - /* body */ { - final long unsignedDividend = ((long) dividend) & 4294967295L; - final long unsignedDivisor = ((long) divisor) & 4294967295L; - result = ((int) (unsignedDividend / unsignedDivisor)); - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::hashCode(int) -> int - * Source: java/lang/Integer.main.lsl:202 - */ - public static int hashCode(int value) { - int result = 0; - /* body */ { - result = value; - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::highestOneBit(int) -> int - * Source: java/lang/Integer.main.lsl:208 - */ - public static int highestOneBit(int i) { - int result = 0; - /* body */ { - i |= i >> 1; - i |= i >> 2; - i |= i >> 4; - i |= i >> 8; - i |= i >> 16; - result = i - (i >>> 1); - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::lowestOneBit(int) -> int - * Source: java/lang/Integer.main.lsl:220 - */ - public static int lowestOneBit(int i) { - int result = 0; - /* body */ { - result = i & -i; - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::max(int, int) -> int - * Source: java/lang/Integer.main.lsl:227 - */ - public static int max(int a, int b) { - int result = 0; - /* body */ { - if (a > b) { - result = a; - } else { - result = b; - } - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::min(int, int) -> int - * Source: java/lang/Integer.main.lsl:236 - */ - public static int min(int a, int b) { - int result = 0; - /* body */ { - if (a < b) { - result = a; - } else { - result = b; - } - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::numberOfLeadingZeros(int) -> int - * Source: java/lang/Integer.main.lsl:245 - */ - public static int numberOfLeadingZeros(int i) { - int result = 0; - /* body */ { - if (i == 0) { - result = 32; - } else { - result = 1; - if ((i >>> 16) == 0) { - result += 16; - i <<= 16; - } - if ((i >>> 24) == 0) { - result += 8; - i <<= 8; - } - if ((i >>> 28) == 0) { - result += 4; - i <<= 4; - } - if ((i >>> 30) == 0) { - result += 2; - i <<= 2; - } - result -= i >>> 31; - } - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::numberOfTrailingZeros(int) -> int - * Source: java/lang/Integer.main.lsl:266 - */ - public static int numberOfTrailingZeros(int i) { - int result = 0; - /* body */ { - if (i == 0) { - result = 32; - } else { - int y = 0; - result = 31; - y = i << 16; - if (y != 0) { - result -= 16; - i = y; - } - y = i << 8; - if (y != 0) { - result -= 8; - i = y; - } - y = i << 4; - if (y != 0) { - result -= 4; - i = y; - } - y = i << 2; - if (y != 0) { - result -= 2; - i = y; - } - result -= (i << 1) >>> 31; - } - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::remainderUnsigned(int, int) -> int - * Source: java/lang/Integer.main.lsl:330 - */ - public static int remainderUnsigned(int dividend, int divisor) { - int result = 0; - /* body */ { - final long unsignedDividend = ((long) dividend) & 4294967295L; - final long unsignedDivisor = ((long) divisor) & 4294967295L; - result = ((int) (unsignedDividend % unsignedDivisor)); - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::reverse(int) -> int - * Source: java/lang/Integer.main.lsl:338 - */ - public static int reverse(int i) { - int result = 0; - /* body */ { - i = (((i & 1431655765) << 1) | (i >>> 1)) & 1431655765; - i = (((i & 858993459) << 2) | (i >>> 2)) & 858993459; - i = (((i & 252645135) << 4) | (i >>> 4)) & 252645135; - i = (i << 24) | ((i & 65280) << 8) | ((i >>> 8) & 65280) | (i >>> 24); - result = i; - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::reverseBytes(int) -> int - * Source: java/lang/Integer.main.lsl:351 - */ - public static int reverseBytes(int i) { - int result = 0; - /* body */ { - result = (i >>> 24) | ((i >> 8) & 65280) | ((i << 8) & 16711680) | (i << 24); - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::rotateLeft(int, int) -> int - * Source: java/lang/Integer.main.lsl:361 - */ - public static int rotateLeft(int i, int distance) { - int result = 0; - /* body */ { - result = (i << distance) | (i >>> -distance); - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::rotateRight(int, int) -> int - * Source: java/lang/Integer.main.lsl:368 - */ - public static int rotateRight(int i, int distance) { - int result = 0; - /* body */ { - result = (i >>> distance) | (i << -distance); - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::signum(int) -> int - * Source: java/lang/Integer.main.lsl:375 - */ - public static int signum(int i) { - int result = 0; - /* body */ { - result = (i >> 31) | (-i >>> 31); - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::sum(int, int) -> int - * Source: java/lang/Integer.main.lsl:382 - */ - public static int sum(int a, int b) { - int result = 0; - /* body */ { - result = a + b; - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::toString(int) -> String - * Source: java/lang/Integer.main.lsl:406 - */ - public static String toString(int i) { - String result = null; - /* body */ { - result = LibSLRuntime.toString(i); - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::toUnsignedLong(int) -> long - * Source: java/lang/Integer.main.lsl:418 - */ - public static long toUnsignedLong(int x) { - long result = 0L; - /* body */ { - result = ((long) x) & 4294967295L; - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::valueOf(int) -> Integer - * Source: java/lang/Integer.main.lsl:451 - */ - public static java.lang.Integer valueOf(int i) { - java.lang.Integer result = null; - /* body */ { - result = (java.lang.Integer) ((Object) new Integer((Void) null, - /* state = */ Integer.__$lsl_States.Initialized, - /* value = */ i - )); - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::byteValue(LSLInteger) -> byte - * Source: java/lang/Integer.main.lsl:461 - */ - public byte byteValue() { - byte result = ((byte) 0); - /* body */ { - result = ((byte) this.value); - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::compareTo(LSLInteger, LSLInteger) -> int - * Source: java/lang/Integer.main.lsl:467 - */ - public int compareTo(Integer anotherInteger) { - int result = 0; - /* body */ { - final int x = this.value; - final int y = ((Integer) ((Object) anotherInteger)).value; - if (x == y) { - result = 0; - } else { - if (x < y) { - result = -1; - } else { - result = 1; - } - } - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::doubleValue(LSLInteger) -> double - * Source: java/lang/Integer.main.lsl:486 - */ - public double doubleValue() { - double result = 0.0d; - /* body */ { - result = ((double) this.value); - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::equals(LSLInteger, Object) -> boolean - * Source: java/lang/Integer.main.lsl:492 - */ - public boolean equals(Object obj) { - boolean result = false; - /* body */ { - if ((obj instanceof java.lang.Integer)) { - result = this.value == ((Integer) ((Object) obj)).value; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::floatValue(LSLInteger) -> float - * Source: java/lang/Integer.main.lsl:501 - */ - public float floatValue() { - float result = 0.0f; - /* body */ { - result = ((float) this.value); - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::hashCode(LSLInteger) -> int - * Source: java/lang/Integer.main.lsl:507 - */ - public int hashCode() { - int result = 0; - /* body */ { - result = this.value; - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::intValue(LSLInteger) -> int - * Source: java/lang/Integer.main.lsl:513 - */ - public int intValue() { - int result = 0; - /* body */ { - result = this.value; - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::longValue(LSLInteger) -> long - * Source: java/lang/Integer.main.lsl:519 - */ - public long longValue() { - long result = 0L; - /* body */ { - result = ((long) this.value); - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::shortValue(LSLInteger) -> short - * Source: java/lang/Integer.main.lsl:525 - */ - public short shortValue() { - short result = ((short) 0); - /* body */ { - result = ((short) this.value); - } - return result; - } - - /** - * [FUNCTION] IntegerAutomaton::toString(LSLInteger) -> String - * Source: java/lang/Integer.main.lsl:531 - */ - public String toString() { - String result = null; - /* body */ { - result = LibSLRuntime.toString(this.value); - } - return result; - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(Integer.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/lang/IntegerImpl.java b/approximations/src/main/java/generated/java/lang/IntegerImpl.java new file mode 100644 index 00000000..54de34f7 --- /dev/null +++ b/approximations/src/main/java/generated/java/lang/IntegerImpl.java @@ -0,0 +1,276 @@ +package generated.java.lang; + +import java.io.Serial; +import java.io.Serializable; +import java.lang.Comparable; +import java.lang.NullPointerException; +import java.lang.Object; +import java.lang.String; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +@SuppressWarnings("unused") +@Approximate(java.lang.Integer.class) +public final class IntegerImpl implements Comparable, Serializable { + + @Serial + private static final long serialVersionUID = 1360826667806852920L; + + public static final int MIN_VALUE = -2147483648; + + public static final int MAX_VALUE = 2147483647; + + public static final int SIZE = 32; + + public static final int BYTES = 4; + + public static final char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; + + public static final char[] DigitTens = { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '3', '3', '3', '3', '3', '3', '3', '3', '3', '3', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5', '6', '6', '6', '6', '6', '6', '6', '6', '6', '6', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '9', '9', '9', '9', '9', '9', '9', '9', '9', '9' }; + + public static final char[] DigitOnes = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; + + public static final int[] sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, 2147483647 }; + + private static final IntegerImpl[] cache; + private static final int cacheLow = -128; + private static final int cacheHigh = 127; + + static { + int cacheSize = cacheHigh - cacheLow + 1; + cache = new IntegerImpl[cacheSize]; + for (int i = 0; i < cacheSize; i++) { + cache[i] = new IntegerImpl(cacheLow + i); + } + } + + private final int value; + + public IntegerImpl(int value) { + this.value = value; + } + + private static int _parse(String str) throws java.lang.NumberFormatException { + if (str == null) + throw new NullPointerException(); + LibSLRuntime.todo(); + return 0; + } + + public static int bitCount(int i) { + i = i - ((i >>> 1) & 1431655765); + i = (i & 858993459) + ((i >>> 2) & 858993459); + i = (i + (i >>> 4)) & 252645135; + i = i + (i >>> 8); + i = i + (i >>> 16); + return i & 63; + } + + @SuppressWarnings("UseCompareMethod") + public static int compare(int x, int y) { + if (x == y) + return 0; + + if (x < y) + return -1; + + return 1; + } + + public static int compareUnsigned(int x, int y) { + x += MIN_VALUE; + y += MIN_VALUE; + return compare(x, y); + } + + public static int divideUnsigned(int dividend, int divisor) { + long unsignedDividend = ((long) dividend) & 4294967295L; + long unsignedDivisor = ((long) divisor) & 4294967295L; + return (int) (unsignedDividend / unsignedDivisor); + } + + public static int hashCode(int value) { + return value; + } + + public static int highestOneBit(int i) { + i |= i >> 1; + i |= i >> 2; + i |= i >> 4; + i |= i >> 8; + i |= i >> 16; + return i - (i >>> 1); + } + + public static int lowestOneBit(int i) { + return i & -i; + } + + @SuppressWarnings("ManualMinMaxCalculation") + public static int max(int a, int b) { + if (a > b) + return a; + + return b; + } + + @SuppressWarnings("ManualMinMaxCalculation") + public static int min(int a, int b) { + if (a < b) + return a; + + return b; + } + + public static int numberOfLeadingZeros(int i) { + if (i == 0) + return 32; + + int result = 1; + if ((i >>> 16) == 0) { + result += 16; + i <<= 16; + } + if ((i >>> 24) == 0) { + result += 8; + i <<= 8; + } + if ((i >>> 28) == 0) { + result += 4; + i <<= 4; + } + if ((i >>> 30) == 0) { + result += 2; + i <<= 2; + } + result -= i >>> 31; + + return result; + } + + public static int numberOfTrailingZeros(int i) { + if (i == 0) + return 32; + + int y; + int result = 31; + y = i << 16; + if (y != 0) { + result -= 16; + i = y; + } + y = i << 8; + if (y != 0) { + result -= 8; + i = y; + } + y = i << 4; + if (y != 0) { + result -= 4; + i = y; + } + y = i << 2; + if (y != 0) { + result -= 2; + i = y; + } + result -= (i << 1) >>> 31; + + return result; + } + + public static int remainderUnsigned(int dividend, int divisor) { + long unsignedDividend = ((long) dividend) & 4294967295L; + long unsignedDivisor = ((long) divisor) & 4294967295L; + return (int) (unsignedDividend % unsignedDivisor); + } + + public static int reverse(int i) { + i = (((i & 1431655765) << 1) | (i >>> 1)) & 1431655765; + i = (((i & 858993459) << 2) | (i >>> 2)) & 858993459; + i = (((i & 252645135) << 4) | (i >>> 4)) & 252645135; + i = (i << 24) | ((i & 65280) << 8) | ((i >>> 8) & 65280) | (i >>> 24); + return i; + } + + public static int reverseBytes(int i) { + return (i >>> 24) | ((i >> 8) & 65280) | ((i << 8) & 16711680) | (i << 24); + } + + public static int rotateLeft(int i, int distance) { + return (i << distance) | (i >>> -distance); + } + + public static int rotateRight(int i, int distance) { + return (i >>> distance) | (i << -distance); + } + + public static int signum(int i) { + return (i >> 31) | (-i >>> 31); + } + + public static int sum(int a, int b) { + return a + b; + } + + public static String toString(int i) { + return LibSLRuntime.toString(i); + } + + public static long toUnsignedLong(int x) { + return ((long) x) & 4294967295L; + } + + public static IntegerImpl valueOf(int i) { + if (i >= cacheLow && i <= cacheHigh) { + return cache[i - cacheLow]; + } + return new IntegerImpl(i); + } + + public byte byteValue() { + return (byte) this.value; + } + + public int compareTo(IntegerImpl anotherInteger) { + return compare(this.value, anotherInteger.value); + } + + public double doubleValue() { + return this.value; + } + + @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") + public boolean equals(Object obj) { + if (Engine.typeIs(obj, IntegerImpl.class)) + return this.value == ((IntegerImpl) obj).value; + + return false; + } + + public float floatValue() { + return (float) this.value; + } + + public int hashCode() { + return this.value; + } + + public int intValue() { + return this.value; + } + + public long longValue() { + return this.value; + } + + public short shortValue() { + return (short) this.value; + } + + public String toString() { + return LibSLRuntime.toString(this.value); + } +} diff --git a/approximations/src/main/java/generated/java/lang/Object.java b/approximations/src/main/java/generated/java/lang/Object.java deleted file mode 100644 index 361f86d7..00000000 --- a/approximations/src/main/java/generated/java/lang/Object.java +++ /dev/null @@ -1,82 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/lang/Object.lsl:30 -// - java/lang/Object.main.lsl:19 -// -package generated.java.lang; - -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * ObjectAutomaton for LSLObject ~> java.lang.Object - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.lang.Object.class) -public class Object implements LibSLRuntime.Automaton { - static { - /* ObjectAutomaton::() */ { - Engine.assume(true); - } - } - - @LibSLRuntime.AutomatonConstructor - public Object(Void __$lsl_token, final byte p0) { - } - - @LibSLRuntime.AutomatonConstructor - public Object(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized); - } - - /** - * [FUNCTION] ObjectAutomaton::equals(LSLObject, Object) -> boolean - * Source: java/lang/Object.main.lsl:61 - */ - public boolean equals(java.lang.Object obj) { - boolean result = false; - /* body */ { - result = this == obj; - } - return result; - } - - /** - * [FUNCTION] ObjectAutomaton::hashCode(LSLObject) -> int - * Source: java/lang/Object.main.lsl:87 - */ - public int hashCode() { - int result = 0; - /* body */ { - result = Engine.makeSymbolicInt(); - } - return result; - } - - /** - * [FUNCTION] ObjectAutomaton::toString(LSLObject) -> String - * Source: java/lang/Object.main.lsl:105 - */ - public String toString() { - String result = null; - /* body */ { - result = "java.lang.Object@735b5592"; - } - return result; - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(Object.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/lang/ObjectImpl.java b/approximations/src/main/java/generated/java/lang/ObjectImpl.java new file mode 100644 index 00000000..5c9c5fb6 --- /dev/null +++ b/approximations/src/main/java/generated/java/lang/ObjectImpl.java @@ -0,0 +1,30 @@ +package generated.java.lang; + +import java.lang.String; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; + +@SuppressWarnings("unused") +@Approximate(java.lang.Object.class) +public class ObjectImpl { + + static { + Engine.assume(true); + } + + // Do not delete this constructor! + public ObjectImpl(Void dummy) {} + + public boolean equals(ObjectImpl obj) { + return this == obj; + } + + public int hashCode() { + return Engine.makeSymbolicInt(); + } + + public String toString() { + return "java.lang.Object@735b5592"; + } +} diff --git a/approximations/src/main/java/generated/java/lang/SecurityManager.java b/approximations/src/main/java/generated/java/lang/SecurityManager.java deleted file mode 100644 index e07f0cc7..00000000 --- a/approximations/src/main/java/generated/java/lang/SecurityManager.java +++ /dev/null @@ -1,457 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/lang/SecurityManager.lsl:31 -// - java/lang/SecurityManager.main.lsl:24 -// -package generated.java.lang; - -import java.io.FileDescriptor; -import java.lang.IllegalArgumentException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SecurityException; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Thread; -import java.lang.ThreadGroup; -import java.lang.Void; -import java.net.InetAddress; -import java.security.AccessControlContext; -import java.security.AccessControlException; -import java.security.Permission; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * SecurityManagerAutomaton for LSLSecurityManager ~> java.lang.SecurityManager - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.lang.SecurityManager.class) -public class SecurityManager implements LibSLRuntime.Automaton { - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - @LibSLRuntime.AutomatonConstructor - public SecurityManager(Void __$lsl_token, final byte p0) { - this.__$lsl_state = p0; - } - - @LibSLRuntime.AutomatonConstructor - public SecurityManager(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated); - } - - /** - * [CONSTRUCTOR] SecurityManagerAutomaton::(LSLSecurityManager) -> void - * Source: java/lang/SecurityManager.main.lsl:100 - */ - public SecurityManager() { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - _do_checkPermission(new RuntimePermission("createSecurityManager")); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] SecurityManagerAutomaton::_do_checkPermission(Permission) -> void - * Source: java/lang/SecurityManager.main.lsl:88 - */ - private void _do_checkPermission(Permission perm) { - /* body */ { - if (Engine.makeSymbolicBoolean()) { - throw new AccessControlException("access denied ", perm); - } - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkAccept(LSLSecurityManager, String, int) -> void - * Source: java/lang/SecurityManager.main.lsl:112 - */ - public void checkAccept(String host, int port) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (host == null) { - throw new NullPointerException(); - } - if (Engine.makeSymbolicBoolean()) { - throw new IllegalArgumentException(); - } - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkAccess(LSLSecurityManager, Thread) -> void - * Source: java/lang/SecurityManager.main.lsl:127 - */ - public void checkAccess(Thread t) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (t == null) { - throw new NullPointerException("thread can\'t be null"); - } - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkAccess(LSLSecurityManager, ThreadGroup) -> void - * Source: java/lang/SecurityManager.main.lsl:140 - */ - public void checkAccess(ThreadGroup g) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (g == null) { - throw new NullPointerException("thread group can\'t be null"); - } - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkConnect(LSLSecurityManager, String, int) -> void - * Source: java/lang/SecurityManager.main.lsl:153 - */ - public void checkConnect(String host, int port) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (host == null) { - throw new NullPointerException("host can\'t be null"); - } - if (Engine.makeSymbolicBoolean()) { - throw new IllegalArgumentException(); - } - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkConnect(LSLSecurityManager, String, int, Object) -> void - * Source: java/lang/SecurityManager.main.lsl:168 - */ - public void checkConnect(String host, int port, Object context) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (host == null) { - throw new NullPointerException("host can\'t be null"); - } - if (Engine.makeSymbolicBoolean()) { - throw new IllegalArgumentException(); - } - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkCreateClassLoader(LSLSecurityManager) -> void - * Source: java/lang/SecurityManager.main.lsl:183 - */ - public void checkCreateClassLoader() { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkDelete(LSLSecurityManager, String) -> void - * Source: java/lang/SecurityManager.main.lsl:191 - */ - public void checkDelete(String file) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (file == null) { - throw new NullPointerException(); - } - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkExec(LSLSecurityManager, String) -> void - * Source: java/lang/SecurityManager.main.lsl:204 - */ - public void checkExec(String cmd) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (cmd == null) { - throw new NullPointerException(); - } - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkExit(LSLSecurityManager, int) -> void - * Source: java/lang/SecurityManager.main.lsl:217 - */ - public void checkExit(int status) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkLink(LSLSecurityManager, String) -> void - * Source: java/lang/SecurityManager.main.lsl:225 - */ - public void checkLink(String lib) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (lib == null) { - throw new NullPointerException(); - } - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkListen(LSLSecurityManager, int) -> void - * Source: java/lang/SecurityManager.main.lsl:236 - */ - public void checkListen(int port) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkMulticast(LSLSecurityManager, InetAddress) -> void - * Source: java/lang/SecurityManager.main.lsl:244 - */ - public void checkMulticast(InetAddress maddr) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (maddr == null) { - throw new NullPointerException(); - } - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkMulticast(LSLSecurityManager, InetAddress, byte) -> void - * Source: java/lang/SecurityManager.main.lsl:255 - */ - public void checkMulticast(InetAddress maddr, byte ttl) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (maddr == null) { - throw new NullPointerException(); - } - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkPackageAccess(LSLSecurityManager, String) -> void - * Source: java/lang/SecurityManager.main.lsl:266 - */ - public void checkPackageAccess(String pkg) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (pkg == null) { - throw new NullPointerException(); - } - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkPackageDefinition(LSLSecurityManager, String) -> void - * Source: java/lang/SecurityManager.main.lsl:277 - */ - public void checkPackageDefinition(String pkg) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (pkg == null) { - throw new NullPointerException(); - } - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkPermission(LSLSecurityManager, Permission) -> void - * Source: java/lang/SecurityManager.main.lsl:288 - */ - public void checkPermission(Permission perm) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (perm == null) { - throw new NullPointerException(); - } - _do_checkPermission(perm); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkPermission(LSLSecurityManager, Permission, Object) -> void - * Source: java/lang/SecurityManager.main.lsl:297 - */ - public void checkPermission(Permission perm, Object context) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if ((context instanceof AccessControlContext)) { - if (perm == null) { - throw new NullPointerException(); - } - _do_checkPermission(perm); - } else { - throw new SecurityException(); - } - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkPrintJobAccess(LSLSecurityManager) -> void - * Source: java/lang/SecurityManager.main.lsl:313 - */ - public void checkPrintJobAccess() { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkPropertiesAccess(LSLSecurityManager) -> void - * Source: java/lang/SecurityManager.main.lsl:321 - */ - public void checkPropertiesAccess() { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkPropertyAccess(LSLSecurityManager, String) -> void - * Source: java/lang/SecurityManager.main.lsl:329 - */ - public void checkPropertyAccess(String key) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkRead(LSLSecurityManager, FileDescriptor) -> void - * Source: java/lang/SecurityManager.main.lsl:337 - */ - public void checkRead(FileDescriptor fd) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkRead(LSLSecurityManager, String) -> void - * Source: java/lang/SecurityManager.main.lsl:345 - */ - public void checkRead(String file) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkRead(LSLSecurityManager, String, Object) -> void - * Source: java/lang/SecurityManager.main.lsl:353 - */ - public void checkRead(String file, Object context) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkSecurityAccess(LSLSecurityManager, String) -> void - * Source: java/lang/SecurityManager.main.lsl:361 - */ - public void checkSecurityAccess(String _target) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_target == null) { - throw new NullPointerException(); - } - if (_target.isEmpty()) { - throw new IllegalArgumentException(); - } - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkSetFactory(LSLSecurityManager) -> void - * Source: java/lang/SecurityManager.main.lsl:375 - */ - public void checkSetFactory() { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkWrite(LSLSecurityManager, FileDescriptor) -> void - * Source: java/lang/SecurityManager.main.lsl:383 - */ - public void checkWrite(FileDescriptor fd) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::checkWrite(LSLSecurityManager, String) -> void - * Source: java/lang/SecurityManager.main.lsl:391 - */ - public void checkWrite(String file) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _do_checkPermission(null); - } - } - - /** - * [FUNCTION] SecurityManagerAutomaton::getSecurityContext(LSLSecurityManager) -> Object - * Source: java/lang/SecurityManager.main.lsl:399 - */ - public Object getSecurityContext() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = Engine.makeSymbolic(AccessControlContext.class); - Engine.assume(result != null); - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(SecurityManager.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/lang/SecurityManagerImpl.java b/approximations/src/main/java/generated/java/lang/SecurityManagerImpl.java new file mode 100644 index 00000000..8b1620df --- /dev/null +++ b/approximations/src/main/java/generated/java/lang/SecurityManagerImpl.java @@ -0,0 +1,194 @@ +package generated.java.lang; + +import java.io.FileDescriptor; +import java.lang.IllegalArgumentException; +import java.lang.NullPointerException; +import java.lang.Object; +import java.lang.SecurityException; +import java.lang.String; +import java.lang.SuppressWarnings; +import java.lang.Thread; +import java.lang.ThreadGroup; +import java.net.InetAddress; +import java.security.Permission; +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; + +@SuppressWarnings({"removal", "unused"}) +@Approximate(java.lang.SecurityManager.class) +public class SecurityManagerImpl { + + static { + Engine.assume(true); + } + + public SecurityManagerImpl() { + _do_checkPermission(new RuntimePermission("createSecurityManager")); + } + + private void _do_checkPermission(Permission perm) { + if (Engine.makeSymbolicBoolean()) + throw new java.security.AccessControlException("access denied ", perm); + } + + private void _do_checkPermission() { + _do_checkPermission(null); + } + + public void checkAccept(String host, int port) { + if (host == null) + throw new NullPointerException(); + if (Engine.makeSymbolicBoolean()) + throw new IllegalArgumentException(); + _do_checkPermission(); + } + + public void checkAccess(Thread t) { + if (t == null) + throw new NullPointerException("thread can't be null"); + _do_checkPermission(); + } + + public void checkAccess(ThreadGroup g) { + if (g == null) + throw new NullPointerException("thread group can't be null"); + _do_checkPermission(); + } + + public void checkConnect(String host, int port) { + if (host == null) + throw new NullPointerException("host can't be null"); + if (Engine.makeSymbolicBoolean()) + throw new IllegalArgumentException(); + _do_checkPermission(); + } + + public void checkConnect(String host, int port, Object context) { + if (host == null) + throw new NullPointerException("host can't be null"); + if (Engine.makeSymbolicBoolean()) + throw new IllegalArgumentException(); + _do_checkPermission(); + } + + public void checkCreateClassLoader() { + _do_checkPermission(); + } + + public void checkDelete(String file) { + if (file == null) + throw new NullPointerException(); + _do_checkPermission(); + } + + public void checkExec(String cmd) { + if (cmd == null) + throw new NullPointerException(); + _do_checkPermission(); + } + + public void checkExit(int status) { + _do_checkPermission(); + } + + public void checkLink(String lib) { + if (lib == null) + throw new NullPointerException(); + _do_checkPermission(); + } + + public void checkListen(int port) { + _do_checkPermission(); + } + + public void checkMulticast(InetAddress maddr) { + if (maddr == null) + throw new NullPointerException(); + _do_checkPermission(); + } + + public void checkMulticast(InetAddress maddr, byte ttl) { + if (maddr == null) + throw new NullPointerException(); + _do_checkPermission(); + } + + public void checkPackageAccess(String pkg) { + if (pkg == null) + throw new NullPointerException(); + _do_checkPermission(); + } + + public void checkPackageDefinition(String pkg) { + if (pkg == null) + throw new NullPointerException(); + _do_checkPermission(); + } + + public void checkPermission(Permission perm) { + if (perm == null) + throw new NullPointerException(); + _do_checkPermission(perm); + } + + public void checkPermission(Permission perm, Object context) { + if (context instanceof java.security.AccessControlContext) { + if (perm == null) + throw new NullPointerException(); + _do_checkPermission(perm); + } else { + throw new SecurityException(); + } + } + + public void checkPrintJobAccess() { + _do_checkPermission(); + } + + public void checkPropertiesAccess() { + _do_checkPermission(); + } + + public void checkPropertyAccess(String key) { + _do_checkPermission(); + } + + public void checkRead(FileDescriptor fd) { + _do_checkPermission(); + } + + public void checkRead(String file) { + _do_checkPermission(); + } + + public void checkRead(String file, Object context) { + _do_checkPermission(); + } + + public void checkSecurityAccess(String _target) { + if (_target == null) + throw new NullPointerException(); + if (_target.isEmpty()) + throw new IllegalArgumentException(); + _do_checkPermission(); + } + + public void checkSetFactory() { + _do_checkPermission(); + } + + public void checkWrite(FileDescriptor fd) { + _do_checkPermission(); + } + + public void checkWrite(String file) { + _do_checkPermission(); + } + + @SuppressWarnings("ConstantValue") + public Object getSecurityContext() { + Object result = Engine.makeSymbolic(java.security.AccessControlContext.class); + Engine.assume(result != null); + return result; + } +} diff --git a/approximations/src/main/java/generated/java/lang/String.java b/approximations/src/main/java/generated/java/lang/String.java deleted file mode 100644 index 11a02398..00000000 --- a/approximations/src/main/java/generated/java/lang/String.java +++ /dev/null @@ -1,313 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/lang/String.lsl:144 -// - java/lang/String.patch.lsl:18 -// -package generated.java.lang; - -import java.io.Serializable; -import java.lang.Object; -import java.lang.StringIndexOutOfBoundsException; -import java.lang.SuppressWarnings; -import java.lang.Void; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * StringAutomaton for LSLString ~> java.lang.String - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.lang.String.class) -public class String implements LibSLRuntime.Automaton, Serializable { - public byte[] value; - - public int length; - - @LibSLRuntime.AutomatonConstructor - public String(Void __$lsl_token, final byte p0, final byte[] p1, final int p2) { - this.value = p1; - this.length = p2; - } - - @LibSLRuntime.AutomatonConstructor - public String(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, 0); - } - - /** - * [CONSTRUCTOR] StringAutomaton::(LSLString) -> void - * Source: java/lang/String.patch.lsl:71 - */ - public String() { - this((Void) null); - /* body */ { - this.value = new byte[0]; - this.length = 0; - } - } - - /** - * [CONSTRUCTOR] StringAutomaton::(LSLString, String) -> void - * Source: java/lang/String.patch.lsl:78 - */ - public String(java.lang.String original) { - this((Void) null); - /* body */ { - this.value = ((String) ((Object) original)).value; - this.length = this.value.length; - } - } - - /** - * [CONSTRUCTOR] StringAutomaton::(LSLString, array) -> void - * Source: java/lang/String.patch.lsl:85 - */ - public String(byte[] bytes) { - this((Void) null); - /* body */ { - final int len = bytes.length; - this.length = len; - this.value = new byte[len]; - LibSLRuntime.ArrayActions.copy(bytes, 0, this.value, 0, len); - } - } - - /** - * [FUNCTION] StringAutomaton::copyValueOf(array) -> String - * Source: java/lang/String.patch.lsl:97 - */ - public static java.lang.String copyValueOf(char[] data) { - java.lang.String result = null; - /* body */ { - result = LibSLRuntime.toString(data); - } - return result; - } - - /** - * [FUNCTION] StringAutomaton::copyValueOf(array, int, int) -> String - * Source: java/lang/String.patch.lsl:103 - */ - public static java.lang.String copyValueOf(char[] data, int offset, int count) { - java.lang.String result = null; - /* body */ { - final char[] segment = new char[count]; - LibSLRuntime.ArrayActions.copy(data, offset, segment, 0, count); - result = LibSLRuntime.toString(segment); - } - return result; - } - - /** - * [FUNCTION] StringAutomaton::valueOf(Object) -> String - * Source: java/lang/String.patch.lsl:112 - */ - public static java.lang.String valueOf(Object x) { - java.lang.String result = null; - /* body */ { - result = LibSLRuntime.toString(x); - } - return result; - } - - /** - * [FUNCTION] StringAutomaton::valueOf(boolean) -> String - * Source: java/lang/String.patch.lsl:118 - */ - public static java.lang.String valueOf(boolean x) { - java.lang.String result = null; - /* body */ { - result = LibSLRuntime.toString(x); - } - return result; - } - - /** - * [FUNCTION] StringAutomaton::valueOf(char) -> String - * Source: java/lang/String.patch.lsl:124 - */ - public static java.lang.String valueOf(char x) { - java.lang.String result = null; - /* body */ { - result = LibSLRuntime.toString(x); - } - return result; - } - - /** - * [FUNCTION] StringAutomaton::valueOf(array) -> String - * Source: java/lang/String.patch.lsl:130 - */ - public static java.lang.String valueOf(char[] data) { - java.lang.String result = null; - /* body */ { - result = LibSLRuntime.toString(data); - } - return result; - } - - /** - * [FUNCTION] StringAutomaton::valueOf(array, int, int) -> String - * Source: java/lang/String.patch.lsl:136 - */ - public static java.lang.String valueOf(char[] data, int offset, int count) { - java.lang.String result = null; - /* body */ { - final char[] segment = new char[count]; - LibSLRuntime.ArrayActions.copy(data, offset, segment, 0, count); - result = LibSLRuntime.toString(segment); - } - return result; - } - - /** - * [FUNCTION] StringAutomaton::valueOf(double) -> String - * Source: java/lang/String.patch.lsl:145 - */ - public static java.lang.String valueOf(double x) { - java.lang.String result = null; - /* body */ { - result = LibSLRuntime.toString(x); - } - return result; - } - - /** - * [FUNCTION] StringAutomaton::valueOf(float) -> String - * Source: java/lang/String.patch.lsl:151 - */ - public static java.lang.String valueOf(float x) { - java.lang.String result = null; - /* body */ { - result = LibSLRuntime.toString(x); - } - return result; - } - - /** - * [FUNCTION] StringAutomaton::valueOf(int) -> String - * Source: java/lang/String.patch.lsl:157 - */ - public static java.lang.String valueOf(int x) { - java.lang.String result = null; - /* body */ { - result = LibSLRuntime.toString(x); - } - return result; - } - - /** - * [FUNCTION] StringAutomaton::valueOf(long) -> String - * Source: java/lang/String.patch.lsl:163 - */ - public static java.lang.String valueOf(long x) { - java.lang.String result = null; - /* body */ { - result = LibSLRuntime.toString(x); - } - return result; - } - - /** - * [FUNCTION] StringAutomaton::concat(LSLString, String) -> String - * Source: java/lang/String.patch.lsl:171 - */ - public java.lang.String concat(java.lang.String str) { - java.lang.String result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= 50); - Engine.assume(this.length == this.value.length); - final byte[] otherVal = ((String) ((Object) str)).value; - final int otherLen = otherVal.length; - if (otherLen == 0) { - result = ((java.lang.String) ((Object) this)); - } else { - final int newLength = this.length + otherLen; - final byte[] newValue = new byte[newLength]; - LibSLRuntime.ArrayActions.copy(this.value, 0, newValue, 0, this.length); - LibSLRuntime.ArrayActions.copy(otherVal, 0, newValue, this.length, otherLen); - result = (java.lang.String) ((Object) new String((Void) null, - /* state = */ String.__$lsl_States.Initialized, - /* value = */ newValue, - /* length = */ newLength - )); - } - } - return result; - } - - /** - * [FUNCTION] StringAutomaton::getBytes(LSLString) -> array - * Source: java/lang/String.patch.lsl:198 - */ - public byte[] getBytes() { - byte[] result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= 50); - Engine.assume(this.length == this.value.length); - result = this.value; - } - return result; - } - - /** - * [FUNCTION] StringAutomaton::getBytes(LSLString, int, int, array, int) -> void - * Source: java/lang/String.patch.lsl:206 - */ - public void getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin) { - /* body */ { - if (srcBegin < 0) { - throw new StringIndexOutOfBoundsException(srcBegin); - } - if (this.length < srcEnd) { - throw new StringIndexOutOfBoundsException(srcEnd); - } - final int count = srcEnd - srcBegin; - if (count < 0) { - throw new StringIndexOutOfBoundsException(count); - } - Engine.assume(this.value != null); - Engine.assume(this.value.length <= 50); - Engine.assume(this.length == this.value.length); - LibSLRuntime.ArrayActions.copy(this.value, srcBegin, dst, dstBegin, count); - } - } - - /** - * [FUNCTION] StringAutomaton::isEmpty(LSLString) -> boolean - * Source: java/lang/String.patch.lsl:223 - */ - public boolean isEmpty() { - boolean result = false; - /* body */ { - result = this.length == 0; - } - return result; - } - - /** - * [FUNCTION] StringAutomaton::length(LSLString) -> int - * Source: java/lang/String.patch.lsl:229 - */ - public int length() { - int result = 0; - /* body */ { - result = this.length; - } - return result; - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(String.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/lang/StringBuffer.java b/approximations/src/main/java/generated/java/lang/StringBuffer.java deleted file mode 100644 index 2aacd208..00000000 --- a/approximations/src/main/java/generated/java/lang/StringBuffer.java +++ /dev/null @@ -1,1333 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/lang/StringBuffer.lsl:31 -// - java/lang/StringBuffer.main.lsl:20 -// -package generated.java.lang; - -import java.io.Serializable; -import java.lang.CharSequence; -import java.lang.Character; -import java.lang.Comparable; -import java.lang.IllegalArgumentException; -import java.lang.IndexOutOfBoundsException; -import java.lang.NegativeArraySizeException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.OutOfMemoryError; -import java.lang.String; -import java.lang.StringIndexOutOfBoundsException; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.stream.IntStream; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; -import stub.java.util.stream.IntStreamLSL; - -/** - * StringBufferAutomaton for LSLStringBuffer ~> java.lang.StringBuffer - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.lang.StringBuffer.class) -public final class StringBuffer implements LibSLRuntime.Automaton, Serializable, Comparable, CharSequence { - private static final long serialVersionUID = 3388685877147921107L; - - private static final int STRINGBUFFER_LENGTH_MAX = 50; - - static { - Engine.assume(true); - } - - public char[] value; - - public int count; - - @LibSLRuntime.AutomatonConstructor - public StringBuffer(Void __$lsl_token, final byte p0, final char[] p1, final int p2) { - this.value = p1; - this.count = p2; - } - - @LibSLRuntime.AutomatonConstructor - public StringBuffer(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, 0); - } - - /** - * [CONSTRUCTOR] StringBufferAutomaton::(LSLStringBuffer) -> void - * Source: java/lang/StringBuffer.main.lsl:238 - */ - public StringBuffer() { - this((Void) null); - /* body */ { - this.value = new char[STRINGBUFFER_LENGTH_MAX]; - } - } - - /** - * [CONSTRUCTOR] StringBufferAutomaton::(LSLStringBuffer, CharSequence) -> void - * Source: java/lang/StringBuffer.main.lsl:244 - */ - public StringBuffer(CharSequence seq) { - this((Void) null); - /* body */ { - if (seq == null) { - throw new NullPointerException(); - } - this.value = new char[STRINGBUFFER_LENGTH_MAX]; - _appendCharSequence(seq, 0, seq.length()); - } - } - - /** - * [CONSTRUCTOR] StringBufferAutomaton::(LSLStringBuffer, String) -> void - * Source: java/lang/StringBuffer.main.lsl:255 - */ - public StringBuffer(String str) { - this((Void) null); - /* body */ { - if (str == null) { - throw new NullPointerException(); - } - this.value = new char[STRINGBUFFER_LENGTH_MAX]; - _appendCharSequence(str, 0, str.length()); - } - } - - /** - * [CONSTRUCTOR] StringBufferAutomaton::(LSLStringBuffer, int) -> void - * Source: java/lang/StringBuffer.main.lsl:266 - */ - public StringBuffer(int cap) { - this((Void) null); - /* body */ { - if (cap < 0) { - throw new NegativeArraySizeException(); - } - if (cap > 1073741823) { - throw new OutOfMemoryError("Requested array size exceeds VM limit"); - } - this.value = new char[STRINGBUFFER_LENGTH_MAX]; - } - } - - /** - * [SUBROUTINE] StringBufferAutomaton::_appendCharSequence(CharSequence, int, int) -> void - * Source: java/lang/StringBuffer.main.lsl:117 - */ - private void _appendCharSequence(CharSequence seq, int seqStart, int seqEnd) { - /* body */ { - if ((seqStart < 0) || (seqStart > seqEnd) || (seqEnd > seq.length())) { - throw new IndexOutOfBoundsException(); - } - final int avaiable = this.value.length - this.count; - int len = seqEnd - seqStart; - if (len > avaiable) { - len = avaiable; - } - if (len > 0) { - String str = null; - if ((seq instanceof String)) { - str = ((String) seq); - } else { - str = LibSLRuntime.toString(seq); - } - final char[] chars = str.toCharArray(); - LibSLRuntime.ArrayActions.copy(chars, seqStart, this.value, this.count, len); - this.count += len; - } - } - } - - /** - * [SUBROUTINE] StringBufferAutomaton::_asString(int, int) -> String - * Source: java/lang/StringBuffer.main.lsl:146 - */ - private String _asString(int posStart, int posEnd) { - String result = null; - /* body */ { - final int len = posEnd - posStart; - if (len == 0) { - result = ""; - } else { - final char[] symbols = new char[len]; - LibSLRuntime.ArrayActions.copy(this.value, posStart, symbols, 0, len); - result = LibSLRuntime.toString(this.value); - } - } - return result; - } - - /** - * [SUBROUTINE] StringBufferAutomaton::_asString() -> String - * Source: java/lang/StringBuffer.main.lsl:162 - */ - public String _asString() { - String result = null; - /* body */ { - final int len = this.count; - if (len == 0) { - result = ""; - } else { - if (len == this.value.length) { - result = LibSLRuntime.toString(this.value); - } else { - final char[] symbols = new char[len]; - LibSLRuntime.ArrayActions.copy(this.value, 0, symbols, 0, len); - result = LibSLRuntime.toString(this.value); - } - } - } - return result; - } - - /** - * [SUBROUTINE] StringBufferAutomaton::_insertCharSequence(int, CharSequence, int, int) -> void - * Source: java/lang/StringBuffer.main.lsl:182 - */ - private void _insertCharSequence(int offset, CharSequence seq, int seqStart, int seqEnd) { - /* body */ { - if ((seqStart < 0) || (seqStart > seqEnd) || (seqEnd > seq.length()) || (offset > this.count)) { - throw new IndexOutOfBoundsException(); - } - final int avaiable = this.value.length - offset; - int len = seqEnd - seqStart; - if (len > avaiable) { - len = avaiable; - } - if (len > 0) { - final int avaiableForLeftovers = avaiable - len; - if (avaiableForLeftovers > 0) { - int rightLeftovers = this.count - offset; - if (rightLeftovers > avaiableForLeftovers) { - rightLeftovers = avaiableForLeftovers; - } - if (rightLeftovers > 0) { - final int rightIndex = offset + 1; - LibSLRuntime.ArrayActions.copy(this.value, rightIndex, this.value, rightIndex + len, rightLeftovers); - } - } - String str = null; - if ((seq instanceof String)) { - str = ((String) seq); - } else { - str = LibSLRuntime.toString(seq); - } - final char[] chars = str.toCharArray(); - LibSLRuntime.ArrayActions.copy(chars, seqStart, this.value, offset, len); - this.count += len; - } - } - } - - /** - * [SUBROUTINE] StringBufferAutomaton::_deleteChars(int, int) -> void - * Source: java/lang/StringBuffer.main.lsl:223 - */ - private void _deleteChars(int start, int end) { - /* body */ { - if ((start < 0) || (start > end) || (end > this.count)) { - throw new IndexOutOfBoundsException(); - } - final int leftovers = this.count - end; - if (leftovers > 0) { - LibSLRuntime.ArrayActions.copy(this.value, end, this.value, start, leftovers); - } - this.count -= end - start; - } - } - - /** - * [FUNCTION] StringBufferAutomaton::append(LSLStringBuffer, CharSequence) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:281 - */ - public synchronized StringBuffer append(CharSequence seq) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (seq == null) { - _appendCharSequence("null", 0, 4); - } else { - _appendCharSequence(seq, 0, seq.length()); - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::append(LSLStringBuffer, CharSequence, int, int) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:294 - */ - public synchronized StringBuffer append(CharSequence seq, int start, int end) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (seq == null) { - _appendCharSequence("null", start, end); - } else { - _appendCharSequence(seq, start, end); - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::append(LSLStringBuffer, Object) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:307 - */ - public synchronized StringBuffer append(Object obj) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (obj == null) { - _appendCharSequence("null", 0, 4); - } else { - final String seq = LibSLRuntime.toString(obj); - _appendCharSequence(seq, 0, seq.length()); - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::append(LSLStringBuffer, String) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:325 - */ - public synchronized StringBuffer append(String str) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (str == null) { - _appendCharSequence("null", 0, 4); - } else { - _appendCharSequence(str, 0, str.length()); - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::append(LSLStringBuffer, StringBuffer) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:338 - */ - public synchronized StringBuffer append(java.lang.StringBuffer sb) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (sb == null) { - _appendCharSequence("null", 0, 4); - } else { - final String seq = LibSLRuntime.toString(sb); - _appendCharSequence(seq, 0, seq.length()); - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::append(LSLStringBuffer, boolean) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:356 - */ - public synchronized StringBuffer append(boolean x) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (x) { - _appendCharSequence("true", 0, 4); - } else { - _appendCharSequence("false", 0, 5); - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::append(LSLStringBuffer, char) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:369 - */ - public synchronized StringBuffer append(char x) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (this.count < this.value.length) { - value[this.count] = x; - this.count += 1; - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::append(LSLStringBuffer, array) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:383 - */ - public synchronized StringBuffer append(char[] str) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String seq = LibSLRuntime.toString(str); - _appendCharSequence(seq, 0, seq.length()); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::append(LSLStringBuffer, array, int, int) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:394 - */ - public synchronized StringBuffer append(char[] str, int offset, int len) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String seq = LibSLRuntime.toString(str); - _appendCharSequence(seq, offset, len); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::append(LSLStringBuffer, double) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:405 - */ - public synchronized StringBuffer append(double x) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String seq = LibSLRuntime.toString(x); - _appendCharSequence(seq, 0, seq.length()); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::append(LSLStringBuffer, float) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:416 - */ - public synchronized StringBuffer append(float x) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String seq = LibSLRuntime.toString(x); - _appendCharSequence(seq, 0, seq.length()); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::append(LSLStringBuffer, int) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:427 - */ - public synchronized StringBuffer append(int x) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String seq = LibSLRuntime.toString(x); - _appendCharSequence(seq, 0, seq.length()); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::append(LSLStringBuffer, long) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:438 - */ - public synchronized StringBuffer append(long x) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String seq = LibSLRuntime.toString(x); - _appendCharSequence(seq, 0, seq.length()); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::appendCodePoint(LSLStringBuffer, int) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:449 - */ - public synchronized StringBuffer appendCodePoint(int codePoint) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final int cnt = this.count; - final int len = this.value.length; - if (Character.isBmpCodePoint(codePoint)) { - if ((cnt + 1) <= len) { - value[cnt] = ((char) codePoint); - this.count = cnt + 1; - } - } else { - if (Character.isValidCodePoint(codePoint)) { - if ((cnt + 2) <= len) { - value[cnt + 1] = Character.lowSurrogate(codePoint); - value[cnt] = Character.highSurrogate(codePoint); - this.count = cnt + 2; - } - } else { - throw new IllegalArgumentException(); - } - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::capacity(LSLStringBuffer) -> int - * Source: java/lang/StringBuffer.main.lsl:486 - */ - public synchronized int capacity() { - int result = 0; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - result = this.value.length; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::charAt(LSLStringBuffer, int) -> char - * Source: java/lang/StringBuffer.main.lsl:494 - */ - public synchronized char charAt(int index) { - char result = '?'; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if ((index < 0) || (index >= this.count)) { - throw new StringIndexOutOfBoundsException(); - } - result = value[index]; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::chars(LSLStringBuffer) -> IntStream - * Source: java/lang/StringBuffer.main.lsl:506 - */ - public IntStream chars() { - IntStream result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final int len = this.count; - final int[] intValues = new int[len]; - int i = 0; - for (i = 0; i < len; i += 1) { - intValues[i] = ((int) value[i]); - } - ; - result = (IntStreamLSL) ((Object) new generated.java.util.stream.IntStreamLSL((Void) null, - /* state = */ generated.java.util.stream.IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ intValues, - /* length = */ len, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::codePointAt(LSLStringBuffer, int) -> int - * Source: java/lang/StringBuffer.main.lsl:532 - */ - public synchronized int codePointAt(int index) { - int result = 0; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if ((index < 0) || (index >= this.count)) { - throw new StringIndexOutOfBoundsException(index); - } - result = Character.codePointAt(this.value, index, this.count); - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::codePointBefore(LSLStringBuffer, int) -> int - * Source: java/lang/StringBuffer.main.lsl:543 - */ - public synchronized int codePointBefore(int index) { - int result = 0; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final int i = index - 1; - if ((i < 0) || (i >= this.count)) { - throw new StringIndexOutOfBoundsException(index); - } - result = Character.codePointBefore(this.value, index, 0); - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::codePointCount(LSLStringBuffer, int, int) -> int - * Source: java/lang/StringBuffer.main.lsl:555 - */ - public synchronized int codePointCount(int beginIndex, int endIndex) { - int result = 0; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if ((beginIndex < 0) || (beginIndex > endIndex) || (endIndex > this.count)) { - throw new IndexOutOfBoundsException(); - } - result = Character.codePointCount(this.value, beginIndex, endIndex - beginIndex); - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::codePoints(LSLStringBuffer) -> IntStream - * Source: java/lang/StringBuffer.main.lsl:567 - */ - public IntStream codePoints() { - IntStream result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final int len = this.count; - final int[] intValues = new int[len]; - int i = 0; - for (i = 0; i < len; i += 1) { - intValues[i] = ((int) value[i]); - } - ; - result = (IntStreamLSL) ((Object) new generated.java.util.stream.IntStreamLSL((Void) null, - /* state = */ generated.java.util.stream.IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ intValues, - /* length = */ len, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::compareTo(LSLStringBuffer, LSLStringBuffer) -> int - * Source: java/lang/StringBuffer.main.lsl:588 - */ - public synchronized int compareTo(StringBuffer another) { - int result = 0; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (another == this) { - result = 0; - } else { - final String thisString = _asString(); - final String anotherString = ((StringBuffer) ((Object) another))._asString(); - result = thisString.compareTo(anotherString); - } - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::delete(LSLStringBuffer, int, int) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:606 - */ - public synchronized StringBuffer delete(int start, int end) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - _deleteChars(start, end); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::deleteCharAt(LSLStringBuffer, int) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:616 - */ - public synchronized StringBuffer deleteCharAt(int index) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - _deleteChars(index, index + 1); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::ensureCapacity(LSLStringBuffer, int) -> void - * Source: java/lang/StringBuffer.main.lsl:626 - */ - public synchronized void ensureCapacity(int minimumCapacity) { - /* body */ { - Engine.assume(true); - } - } - - /** - * [FUNCTION] StringBufferAutomaton::getChars(LSLStringBuffer, int, int, array, int) -> void - * Source: java/lang/StringBuffer.main.lsl:633 - */ - public synchronized void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) { - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if ((srcBegin < 0) || (srcBegin > srcEnd) || (srcEnd > this.count)) { - throw new StringIndexOutOfBoundsException(); - } - final int len = srcEnd - srcBegin; - if (dst == null) { - throw new NullPointerException(); - } - if ((dstBegin < 0) || ((dstBegin + len) > dst.length)) { - throw new IndexOutOfBoundsException(); - } - if (len > 0) { - LibSLRuntime.ArrayActions.copy(this.value, srcBegin, dst, dstBegin, len); - } - } - } - - /** - * [FUNCTION] StringBufferAutomaton::getValue(LSLStringBuffer) -> array - * Source: java/lang/StringBuffer.main.lsl:654 - */ - public char[] getValue() { - char[] result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - result = this.value; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::indexOf(LSLStringBuffer, String) -> int - * Source: java/lang/StringBuffer.main.lsl:662 - */ - public int indexOf(String str) { - int result = 0; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - result = _asString().indexOf(str, 0); - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::indexOf(LSLStringBuffer, String, int) -> int - * Source: java/lang/StringBuffer.main.lsl:671 - */ - public synchronized int indexOf(String str, int fromIndex) { - int result = 0; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - result = _asString().indexOf(str, fromIndex); - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::insert(LSLStringBuffer, int, CharSequence) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:680 - */ - public StringBuffer insert(int dstOffset, CharSequence s) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (s == null) { - _insertCharSequence(dstOffset, "null", 0, 4); - } else { - _insertCharSequence(dstOffset, s, 0, s.length()); - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::insert(LSLStringBuffer, int, CharSequence, int, int) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:693 - */ - public synchronized StringBuffer insert(int dstOffset, CharSequence s, int start, int end) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (s == null) { - _insertCharSequence(dstOffset, "null", start, end); - } else { - _insertCharSequence(dstOffset, s, start, end); - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::insert(LSLStringBuffer, int, Object) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:706 - */ - public synchronized StringBuffer insert(int dstOffset, Object obj) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (obj == null) { - _insertCharSequence(dstOffset, "null", 0, 4); - } else { - final String s = LibSLRuntime.toString(obj); - _insertCharSequence(dstOffset, s, 0, s.length()); - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::insert(LSLStringBuffer, int, String) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:724 - */ - public synchronized StringBuffer insert(int dstOffset, String s) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (s == null) { - _insertCharSequence(dstOffset, "null", 0, 4); - } else { - _insertCharSequence(dstOffset, s, 0, s.length()); - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::insert(LSLStringBuffer, int, boolean) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:737 - */ - public StringBuffer insert(int dstOffset, boolean x) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String s = LibSLRuntime.toString(x); - _insertCharSequence(dstOffset, s, 0, s.length()); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::insert(LSLStringBuffer, int, char) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:748 - */ - public synchronized StringBuffer insert(int dstOffset, char x) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String s = LibSLRuntime.toString(x); - _insertCharSequence(dstOffset, s, 0, 1); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::insert(LSLStringBuffer, int, array) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:759 - */ - public synchronized StringBuffer insert(int dstOffset, char[] x) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String s = LibSLRuntime.toString(x); - _insertCharSequence(dstOffset, s, 0, s.length()); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::insert(LSLStringBuffer, int, array, int, int) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:770 - */ - public synchronized StringBuffer insert(int index, char[] str, int offset, int len) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final char[] arr = new char[len]; - LibSLRuntime.ArrayActions.copy(str, offset, arr, 0, len); - final String s = LibSLRuntime.toString(arr); - _insertCharSequence(index, s, 0, len); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::insert(LSLStringBuffer, int, double) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:784 - */ - public StringBuffer insert(int dstOffset, double x) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String s = LibSLRuntime.toString(x); - _insertCharSequence(dstOffset, s, 0, s.length()); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::insert(LSLStringBuffer, int, float) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:795 - */ - public StringBuffer insert(int dstOffset, float x) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String s = LibSLRuntime.toString(x); - _insertCharSequence(dstOffset, s, 0, s.length()); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::insert(LSLStringBuffer, int, int) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:806 - */ - public StringBuffer insert(int dstOffset, int x) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String s = LibSLRuntime.toString(x); - _insertCharSequence(dstOffset, s, 0, s.length()); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::insert(LSLStringBuffer, int, long) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:817 - */ - public StringBuffer insert(int dstOffset, long x) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String s = LibSLRuntime.toString(x); - _insertCharSequence(dstOffset, s, 0, s.length()); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::lastIndexOf(LSLStringBuffer, String) -> int - * Source: java/lang/StringBuffer.main.lsl:828 - */ - public int lastIndexOf(String str) { - int result = 0; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - result = _asString().lastIndexOf(str, this.count); - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::lastIndexOf(LSLStringBuffer, String, int) -> int - * Source: java/lang/StringBuffer.main.lsl:837 - */ - public synchronized int lastIndexOf(String str, int fromIndex) { - int result = 0; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - result = _asString().lastIndexOf(str, fromIndex); - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::length(LSLStringBuffer) -> int - * Source: java/lang/StringBuffer.main.lsl:846 - */ - public synchronized int length() { - int result = 0; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - result = this.count; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::offsetByCodePoints(LSLStringBuffer, int, int) -> int - * Source: java/lang/StringBuffer.main.lsl:854 - */ - public synchronized int offsetByCodePoints(int index, int codePointOffset) { - int result = 0; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if ((index < 0) || (index > this.count)) { - throw new IndexOutOfBoundsException(); - } - result = Character.offsetByCodePoints(this.value, 0, this.count, index, codePointOffset); - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::replace(LSLStringBuffer, int, int, String) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:865 - */ - public synchronized StringBuffer replace(int start, int end, String s) { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - _deleteChars(start, end); - if (s == null) { - _insertCharSequence(start, "null", 0, 4); - } else { - _insertCharSequence(start, s, 0, s.length()); - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::reverse(LSLStringBuffer) -> LSLStringBuffer - * Source: java/lang/StringBuffer.main.lsl:880 - */ - public synchronized StringBuffer reverse() { - StringBuffer result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (this.count != 0) { - boolean hasSurrogates = false; - final int n = this.count - 1; - int j = 0; - for (j = (n - 1) >> 1; j > -1; j += -1) { - int k = n - j; - char cj = value[j]; - char ck = value[k]; - value[j] = ck; - value[k] = cj; - if (Character.isSurrogate(cj) || Character.isSurrogate(ck)) { - hasSurrogates = true; - } - } - ; - if (hasSurrogates) { - int i = 0; - for (i = 0; i < n; i += 1) { - char c2 = value[i]; - if (Character.isLowSurrogate(c2)) { - char c1 = value[i + 1]; - if (Character.isHighSurrogate(c1)) { - value[i] = c1; - i += 1; - value[i] = c2; - } - } - } - ; - } - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::setCharAt(LSLStringBuffer, int, char) -> void - * Source: java/lang/StringBuffer.main.lsl:942 - */ - public synchronized void setCharAt(int index, char x) { - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if ((index < 0) || (index >= this.count)) { - throw new StringIndexOutOfBoundsException(); - } - value[index] = x; - } - } - - /** - * [FUNCTION] StringBufferAutomaton::setLength(LSLStringBuffer, int) -> void - * Source: java/lang/StringBuffer.main.lsl:953 - */ - public synchronized void setLength(int newLength) { - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final int maxLength = this.value.length; - if (newLength > maxLength) { - newLength = maxLength; - } - if (newLength < 0) { - throw new StringIndexOutOfBoundsException(); - } else { - if (newLength < this.count) { - this.count = newLength; - } else { - if (newLength > this.count) { - LibSLRuntime.ArrayActions.fillRange(this.value, this.count, newLength, ((char) 0)); - this.count = newLength; - } - } - } - } - } - - /** - * [FUNCTION] StringBufferAutomaton::subSequence(LSLStringBuffer, int, int) -> CharSequence - * Source: java/lang/StringBuffer.main.lsl:978 - */ - public synchronized CharSequence subSequence(int start, int end) { - CharSequence result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if ((start < 0) || (start > end) || (end > this.count)) { - throw new StringIndexOutOfBoundsException(); - } - result = _asString(start, end); - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::substring(LSLStringBuffer, int) -> String - * Source: java/lang/StringBuffer.main.lsl:989 - */ - public synchronized String substring(int start) { - String result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if ((start < 0) || (start > this.count)) { - throw new StringIndexOutOfBoundsException(); - } - result = _asString(start, this.count); - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::substring(LSLStringBuffer, int, int) -> String - * Source: java/lang/StringBuffer.main.lsl:1000 - */ - public synchronized String substring(int start, int end) { - String result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if ((start < 0) || (start > end) || (end > this.count)) { - throw new StringIndexOutOfBoundsException(); - } - result = _asString(start, end); - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::toString(LSLStringBuffer) -> String - * Source: java/lang/StringBuffer.main.lsl:1011 - */ - public synchronized String toString() { - String result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - result = _asString(); - } - return result; - } - - /** - * [FUNCTION] StringBufferAutomaton::trimToSize(LSLStringBuffer) -> void - * Source: java/lang/StringBuffer.main.lsl:1019 - */ - public synchronized void trimToSize() { - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUFFER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - } - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(StringBuffer.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/lang/StringBufferImpl.java b/approximations/src/main/java/generated/java/lang/StringBufferImpl.java new file mode 100644 index 00000000..d3410548 --- /dev/null +++ b/approximations/src/main/java/generated/java/lang/StringBufferImpl.java @@ -0,0 +1,643 @@ +package generated.java.lang; + +import java.io.Serial; +import java.io.Serializable; +import java.lang.CharSequence; +import java.lang.Character; +import java.lang.Comparable; +import java.lang.IllegalArgumentException; +import java.lang.IndexOutOfBoundsException; +import java.lang.NegativeArraySizeException; +import java.lang.NullPointerException; +import java.lang.Object; +import java.lang.OutOfMemoryError; +import java.lang.String; +import java.lang.StringIndexOutOfBoundsException; +import java.util.stream.IntStream; + +import generated.java.util.stream.IntStreamImpl; +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +@SuppressWarnings("unused") +@Approximate(java.lang.StringBuffer.class) +public final class StringBufferImpl implements Serializable, Comparable, CharSequence { + + @Serial + private static final long serialVersionUID = 3388685877147921107L; + + private static final int STRING_BUFFER_LENGTH_MAX = 50; + + static { + Engine.assume(true); + } + + public char[] value; + + public int count = 0; + + public StringBufferImpl(char[] value, int count) { + this.value = value; + this.count = count; + } + + public StringBufferImpl() { + this(new char[STRING_BUFFER_LENGTH_MAX], 0); + } + + public StringBufferImpl(CharSequence seq) { + if (seq == null) + throw new NullPointerException(); + this.value = new char[STRING_BUFFER_LENGTH_MAX]; + _appendCharSequence(seq, 0, seq.length()); + } + + public StringBufferImpl(String str) { + if (str == null) { + throw new NullPointerException(); + } + this.value = new char[STRING_BUFFER_LENGTH_MAX]; + _appendCharSequence(str, 0, str.length()); + } + + public StringBufferImpl(int cap) { + if (cap < 0) + throw new NegativeArraySizeException(); + if (cap > 1073741823) + throw new OutOfMemoryError("Requested array size exceeds VM limit"); + this.value = new char[STRING_BUFFER_LENGTH_MAX]; + } + + private void _appendCharSequence(CharSequence seq, int seqStart, int seqEnd) { + if (seqStart < 0 || seqStart > seqEnd || seqEnd > seq.length()) + throw new IndexOutOfBoundsException(); + int available = this.value.length - this.count; + int len = seqEnd - seqStart; + if (len > available) + len = available; + if (len <= 0) + return; + + String str; + if (seq instanceof String) { + str = (String) seq; + } else { + str = LibSLRuntime.toString(seq); + } + char[] chars = str.toCharArray(); + LibSLRuntime.ArrayActions.copy(chars, seqStart, this.value, this.count, len); + this.count += len; + } + + private String _asString(int posStart, int posEnd) { + int len = posEnd - posStart; + if (len == 0) + return ""; + + char[] symbols = new char[len]; + LibSLRuntime.ArrayActions.copy(this.value, posStart, symbols, 0, len); + return LibSLRuntime.toString(this.value); + } + + public String _asString() { + int len = this.count; + if (len == 0) + return ""; + + if (len == this.value.length) + return LibSLRuntime.toString(this.value); + + char[] symbols = new char[len]; + LibSLRuntime.ArrayActions.copy(this.value, 0, symbols, 0, len); + return LibSLRuntime.toString(this.value); + } + + private void _insertCharSequence(int offset, CharSequence seq, int seqStart, int seqEnd) { + if (seqStart < 0 || seqStart > seqEnd || seqEnd > seq.length() || offset > this.count) + throw new IndexOutOfBoundsException(); + + int available = this.value.length - offset; + int len = seqEnd - seqStart; + if (len > available) + len = available; + + if (len <= 0) + return; + + int availableForLeftovers = available - len; + if (availableForLeftovers > 0) { + int rightLeftovers = this.count - offset; + if (rightLeftovers > availableForLeftovers) + rightLeftovers = availableForLeftovers; + if (rightLeftovers > 0) { + int rightIndex = offset + 1; + LibSLRuntime.ArrayActions.copy(this.value, rightIndex, this.value, rightIndex + len, rightLeftovers); + } + } + String str; + if (seq instanceof String) { + str = (String) seq; + } else { + str = LibSLRuntime.toString(seq); + } + char[] chars = str.toCharArray(); + LibSLRuntime.ArrayActions.copy(chars, seqStart, this.value, offset, len); + this.count += len; + } + + private void _deleteChars(int start, int end) { + if (start < 0 || start > end || end > this.count) + throw new IndexOutOfBoundsException(); + + int leftovers = this.count - end; + if (leftovers > 0) + LibSLRuntime.ArrayActions.copy(this.value, end, this.value, start, leftovers); + this.count -= end - start; + } + + @SuppressWarnings("DataFlowIssue") + private void _assumeInvariants() { + Engine.assume(this.value != null); + Engine.assume(this.value.length <= STRING_BUFFER_LENGTH_MAX); + Engine.assume(this.count <= this.value.length); + Engine.assume(this.count >= 0); + } + + public synchronized StringBufferImpl append(CharSequence seq) { + _assumeInvariants(); + if (seq == null) { + _appendCharSequence("null", 0, 4); + } else { + _appendCharSequence(seq, 0, seq.length()); + } + return this; + } + + @SuppressWarnings("ReplaceNullCheck") + public synchronized StringBufferImpl append(CharSequence seq, int start, int end) { + _assumeInvariants(); + if (seq == null) { + _appendCharSequence("null", start, end); + } else { + _appendCharSequence(seq, start, end); + } + return this; + } + + public synchronized StringBufferImpl append(Object obj) { + _assumeInvariants(); + if (obj == null) { + _appendCharSequence("null", 0, 4); + } else { + String seq = LibSLRuntime.toString(obj); + _appendCharSequence(seq, 0, seq.length()); + } + return this; + } + + public synchronized StringBufferImpl append(String str) { + _assumeInvariants(); + if (str == null) { + _appendCharSequence("null", 0, 4); + } else { + _appendCharSequence(str, 0, str.length()); + } + return this; + } + + public synchronized StringBufferImpl append(java.lang.StringBuffer sb) { + _assumeInvariants(); + if (sb == null) { + _appendCharSequence("null", 0, 4); + } else { + String seq = LibSLRuntime.toString(sb); + _appendCharSequence(seq, 0, seq.length()); + } + return this; + } + + public synchronized StringBufferImpl append(boolean x) { + _assumeInvariants(); + if (x) { + _appendCharSequence("true", 0, 4); + } else { + _appendCharSequence("false", 0, 5); + } + return this; + } + + public synchronized StringBufferImpl append(char x) { + _assumeInvariants(); + if (this.count < this.value.length) { + value[this.count] = x; + this.count++; + } + return this; + } + + public synchronized StringBufferImpl append(char[] str) { + _assumeInvariants(); + String seq = LibSLRuntime.toString(str); + _appendCharSequence(seq, 0, seq.length()); + return this; + } + + public synchronized StringBufferImpl append(char[] str, int offset, int len) { + _assumeInvariants(); + String seq = LibSLRuntime.toString(str); + _appendCharSequence(seq, offset, len); + return this; + } + + public synchronized StringBufferImpl append(double x) { + _assumeInvariants(); + String seq = LibSLRuntime.toString(x); + _appendCharSequence(seq, 0, seq.length()); + return this; + } + + public synchronized StringBufferImpl append(float x) { + _assumeInvariants(); + String seq = LibSLRuntime.toString(x); + _appendCharSequence(seq, 0, seq.length()); + return this; + } + + public synchronized StringBufferImpl append(int x) { + _assumeInvariants(); + String seq = LibSLRuntime.toString(x); + _appendCharSequence(seq, 0, seq.length()); + return this; + } + + public synchronized StringBufferImpl append(long x) { + _assumeInvariants(); + String seq = LibSLRuntime.toString(x); + _appendCharSequence(seq, 0, seq.length()); + return this; + } + + public synchronized StringBufferImpl appendCodePoint(int codePoint) { + _assumeInvariants(); + int cnt = this.count; + int len = this.value.length; + if (Character.isBmpCodePoint(codePoint)) { + if (cnt + 1 <= len) { + value[cnt] = (char) codePoint; + this.count = cnt + 1; + } + } else { + if (Character.isValidCodePoint(codePoint)) { + if (cnt + 2 <= len) { + value[cnt + 1] = Character.lowSurrogate(codePoint); + value[cnt] = Character.highSurrogate(codePoint); + this.count = cnt + 2; + } + } else { + throw new IllegalArgumentException(); + } + } + return this; + } + + public synchronized int capacity() { + _assumeInvariants(); + return this.value.length; + } + + public synchronized char charAt(int index) { + _assumeInvariants(); + if (index < 0 || index >= this.count) + throw new StringIndexOutOfBoundsException(); + return value[index]; + } + + @NotNull + public IntStream chars() { + _assumeInvariants(); + int len = this.count; + int[] intValues = new int[len]; + for (int i = 0; i < len; i++) { + intValues[i] = value[i]; + } + + return new IntStreamImpl(intValues); + } + + public synchronized int codePointAt(int index) { + _assumeInvariants(); + if (index < 0 || index >= this.count) + throw new StringIndexOutOfBoundsException(index); + return Character.codePointAt(this.value, index, this.count); + } + + public synchronized int codePointBefore(int index) { + _assumeInvariants(); + int i = index - 1; + if (i < 0 || i >= this.count) + throw new StringIndexOutOfBoundsException(index); + return Character.codePointBefore(this.value, index, 0); + } + + public synchronized int codePointCount(int beginIndex, int endIndex) { + _assumeInvariants(); + if (beginIndex < 0 || beginIndex > endIndex || endIndex > this.count) + throw new IndexOutOfBoundsException(); + return Character.codePointCount(this.value, beginIndex, endIndex - beginIndex); + } + + @NotNull + public IntStream codePoints() { + _assumeInvariants(); + int len = this.count; + int[] intValues = new int[len]; + for (int i = 0; i < len; i++) { + intValues[i] = value[i]; + } + return new IntStreamImpl(intValues); + } + + public synchronized int compareTo(@NotNull StringBufferImpl another) { + _assumeInvariants(); + if (another == this) + return 0; + + String thisString = _asString(); + String anotherString = another._asString(); + return thisString.compareTo(anotherString); + } + + public synchronized StringBufferImpl delete(int start, int end) { + _assumeInvariants(); + _deleteChars(start, end); + return this; + } + + public synchronized StringBufferImpl deleteCharAt(int index) { + _assumeInvariants(); + _deleteChars(index, index + 1); + return this; + } + + public synchronized void ensureCapacity(int minimumCapacity) { + Engine.assume(true); + } + + public synchronized void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) { + _assumeInvariants(); + if (srcBegin < 0 || srcBegin > srcEnd || srcEnd > this.count) + throw new StringIndexOutOfBoundsException(); + int len = srcEnd - srcBegin; + if (dst == null) + throw new NullPointerException(); + if (dstBegin < 0 || dstBegin + len > dst.length) + throw new IndexOutOfBoundsException(); + if (len > 0) + LibSLRuntime.ArrayActions.copy(this.value, srcBegin, dst, dstBegin, len); + } + + public char[] getValue() { + _assumeInvariants(); + return this.value; + } + + public int indexOf(String str) { + _assumeInvariants(); + return _asString().indexOf(str); + } + + public synchronized int indexOf(String str, int fromIndex) { + _assumeInvariants(); + return _asString().indexOf(str, fromIndex); + } + + public StringBufferImpl insert(int dstOffset, CharSequence s) { + _assumeInvariants(); + if (s == null) { + _insertCharSequence(dstOffset, "null", 0, 4); + } else { + _insertCharSequence(dstOffset, s, 0, s.length()); + } + return this; + } + + @SuppressWarnings("ReplaceNullCheck") + public synchronized StringBufferImpl insert(int dstOffset, CharSequence s, int start, int end) { + _assumeInvariants(); + if (s == null) { + _insertCharSequence(dstOffset, "null", start, end); + } else { + _insertCharSequence(dstOffset, s, start, end); + } + return this; + } + + public synchronized StringBufferImpl insert(int dstOffset, Object obj) { + _assumeInvariants(); + if (obj == null) { + _insertCharSequence(dstOffset, "null", 0, 4); + } else { + String s = LibSLRuntime.toString(obj); + _insertCharSequence(dstOffset, s, 0, s.length()); + } + return this; + } + + public synchronized StringBufferImpl insert(int dstOffset, String s) { + _assumeInvariants(); + if (s == null) { + _insertCharSequence(dstOffset, "null", 0, 4); + } else { + _insertCharSequence(dstOffset, s, 0, s.length()); + } + return this; + } + + public StringBufferImpl insert(int dstOffset, boolean x) { + _assumeInvariants(); + String s = LibSLRuntime.toString(x); + _insertCharSequence(dstOffset, s, 0, s.length()); + return this; + } + + public synchronized StringBufferImpl insert(int dstOffset, char x) { + _assumeInvariants(); + String s = LibSLRuntime.toString(x); + _insertCharSequence(dstOffset, s, 0, 1); + return this; + } + + public synchronized StringBufferImpl insert(int dstOffset, char[] x) { + _assumeInvariants(); + String s = LibSLRuntime.toString(x); + _insertCharSequence(dstOffset, s, 0, s.length()); + return this; + } + + public synchronized StringBufferImpl insert(int index, char[] str, int offset, int len) { + _assumeInvariants(); + char[] arr = new char[len]; + LibSLRuntime.ArrayActions.copy(str, offset, arr, 0, len); + String s = LibSLRuntime.toString(arr); + _insertCharSequence(index, s, 0, len); + return this; + } + + public StringBufferImpl insert(int dstOffset, double x) { + _assumeInvariants(); + String s = LibSLRuntime.toString(x); + _insertCharSequence(dstOffset, s, 0, s.length()); + return this; + } + + public StringBufferImpl insert(int dstOffset, float x) { + _assumeInvariants(); + String s = LibSLRuntime.toString(x); + _insertCharSequence(dstOffset, s, 0, s.length()); + return this; + } + + public StringBufferImpl insert(int dstOffset, int x) { + _assumeInvariants(); + String s = LibSLRuntime.toString(x); + _insertCharSequence(dstOffset, s, 0, s.length()); + return this; + } + + public StringBufferImpl insert(int dstOffset, long x) { + _assumeInvariants(); + String s = LibSLRuntime.toString(x); + _insertCharSequence(dstOffset, s, 0, s.length()); + return this; + } + + public int lastIndexOf(String str) { + _assumeInvariants(); + return _asString().lastIndexOf(str, this.count); + } + + public synchronized int lastIndexOf(String str, int fromIndex) { + _assumeInvariants(); + return _asString().lastIndexOf(str, fromIndex); + } + + public synchronized int length() { + _assumeInvariants(); + return this.count; + } + + public synchronized int offsetByCodePoints(int index, int codePointOffset) { + _assumeInvariants(); + if (index < 0 || index > this.count) + throw new IndexOutOfBoundsException(); + return Character.offsetByCodePoints(this.value, 0, this.count, index, codePointOffset); + } + + public synchronized StringBufferImpl replace(int start, int end, String s) { + _assumeInvariants(); + _deleteChars(start, end); + if (s == null) { + _insertCharSequence(start, "null", 0, 4); + } else { + _insertCharSequence(start, s, 0, s.length()); + } + return this; + } + + public synchronized StringBufferImpl reverse() { + _assumeInvariants(); + if (this.count == 0) + return this; + + boolean hasSurrogates = false; + int n = this.count - 1; + for (int i = (n - 1) >> 1; i > -1; i--) { + int k = n - i; + char cj = value[i]; + char ck = value[k]; + value[i] = ck; + value[k] = cj; + if (Character.isSurrogate(cj) || Character.isSurrogate(ck)) + hasSurrogates = true; + } + + if (!hasSurrogates) + return this; + + for (int i = 0; i < n; i++) { + char c2 = value[i]; + if (Character.isLowSurrogate(c2)) { + char c1 = value[i + 1]; + if (Character.isHighSurrogate(c1)) { + value[i] = c1; + i++; + value[i] = c2; + } + } + } + return this; + } + + public synchronized void setCharAt(int index, char x) { + _assumeInvariants(); + if (index < 0 || index >= this.count) + throw new StringIndexOutOfBoundsException(); + value[index] = x; + } + + public synchronized void setLength(int newLength) { + _assumeInvariants(); + int maxLength = this.value.length; + if (newLength > maxLength) + newLength = maxLength; + if (newLength < 0) + throw new StringIndexOutOfBoundsException(); + + if (newLength < this.count) { + this.count = newLength; + return; + } + + if (newLength > this.count) { + LibSLRuntime.ArrayActions.fillRange(this.value, this.count, newLength, ((char) 0)); + this.count = newLength; + } + } + + @NotNull + public synchronized CharSequence subSequence(int start, int end) { + _assumeInvariants(); + if (start < 0 || start > end || end > this.count) + throw new StringIndexOutOfBoundsException(); + + return _asString(start, end); + } + + public synchronized String substring(int start) { + _assumeInvariants(); + if (start < 0 || start > this.count) + throw new StringIndexOutOfBoundsException(); + + return _asString(start, this.count); + } + + public synchronized String substring(int start, int end) { + _assumeInvariants(); + if (start < 0 || start > end || end > this.count) + throw new StringIndexOutOfBoundsException(); + + return _asString(start, end); + } + + @NotNull + public synchronized String toString() { + _assumeInvariants(); + return _asString(); + } + + public synchronized void trimToSize() { + _assumeInvariants(); + } +} diff --git a/approximations/src/main/java/generated/java/lang/StringBuilder.java b/approximations/src/main/java/generated/java/lang/StringBuilder.java deleted file mode 100644 index 276313f8..00000000 --- a/approximations/src/main/java/generated/java/lang/StringBuilder.java +++ /dev/null @@ -1,1357 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/lang/StringBuilder.lsl:30 -// - java/lang/StringBuilder.main.lsl:22 -// -package generated.java.lang; - -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.lang.CharSequence; -import java.lang.Character; -import java.lang.Comparable; -import java.lang.IllegalArgumentException; -import java.lang.IndexOutOfBoundsException; -import java.lang.NegativeArraySizeException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.OutOfMemoryError; -import java.lang.String; -import java.lang.StringBuffer; -import java.lang.StringIndexOutOfBoundsException; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.stream.IntStream; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; -import stub.java.util.stream.IntStreamLSL; - -/** - * StringBuilderAutomaton for LSLStringBuilder ~> java.lang.StringBuilder - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.lang.StringBuilder.class) -public final class StringBuilder implements LibSLRuntime.Automaton, Serializable, Comparable, CharSequence { - private static final long serialVersionUID = 4383685877147921099L; - - private static final int STRINGBUILDER_LENGTH_MAX = 50; - - static { - Engine.assume(true); - } - - public char[] value; - - public int count; - - @LibSLRuntime.AutomatonConstructor - public StringBuilder(Void __$lsl_token, final byte p0, final char[] p1, final int p2) { - this.value = p1; - this.count = p2; - } - - @LibSLRuntime.AutomatonConstructor - public StringBuilder(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, 0); - } - - /** - * [CONSTRUCTOR] StringBuilderAutomaton::(LSLStringBuilder) -> void - * Source: java/lang/StringBuilder.main.lsl:240 - */ - public StringBuilder() { - this((Void) null); - /* body */ { - this.value = new char[STRINGBUILDER_LENGTH_MAX]; - } - } - - /** - * [CONSTRUCTOR] StringBuilderAutomaton::(LSLStringBuilder, CharSequence) -> void - * Source: java/lang/StringBuilder.main.lsl:246 - */ - public StringBuilder(CharSequence seq) { - this((Void) null); - /* body */ { - if (seq == null) { - throw new NullPointerException(); - } - this.value = new char[STRINGBUILDER_LENGTH_MAX]; - _appendCharSequence(seq, 0, seq.length()); - } - } - - /** - * [CONSTRUCTOR] StringBuilderAutomaton::(LSLStringBuilder, String) -> void - * Source: java/lang/StringBuilder.main.lsl:257 - */ - public StringBuilder(String str) { - this((Void) null); - /* body */ { - if (str == null) { - throw new NullPointerException(); - } - this.value = new char[STRINGBUILDER_LENGTH_MAX]; - _appendCharSequence(str, 0, str.length()); - } - } - - /** - * [CONSTRUCTOR] StringBuilderAutomaton::(LSLStringBuilder, int) -> void - * Source: java/lang/StringBuilder.main.lsl:268 - */ - public StringBuilder(int cap) { - this((Void) null); - /* body */ { - if (cap < 0) { - throw new NegativeArraySizeException(); - } - if (cap > 1073741823) { - throw new OutOfMemoryError("Requested array size exceeds VM limit"); - } - this.value = new char[STRINGBUILDER_LENGTH_MAX]; - } - } - - /** - * [SUBROUTINE] StringBuilderAutomaton::_appendCharSequence(CharSequence, int, int) -> void - * Source: java/lang/StringBuilder.main.lsl:119 - */ - private void _appendCharSequence(CharSequence seq, int seqStart, int seqEnd) { - /* body */ { - if ((seqStart < 0) || (seqStart > seqEnd) || (seqEnd > seq.length())) { - throw new IndexOutOfBoundsException(); - } - final int avaiable = this.value.length - this.count; - int len = seqEnd - seqStart; - if (len > avaiable) { - len = avaiable; - } - if (len > 0) { - String str = null; - if ((seq instanceof String)) { - str = ((String) seq); - } else { - str = LibSLRuntime.toString(seq); - } - final char[] chars = str.toCharArray(); - LibSLRuntime.ArrayActions.copy(chars, seqStart, this.value, this.count, len); - this.count += len; - } - } - } - - /** - * [SUBROUTINE] StringBuilderAutomaton::_asString(int, int) -> String - * Source: java/lang/StringBuilder.main.lsl:148 - */ - private String _asString(int posStart, int posEnd) { - String result = null; - /* body */ { - final int len = posEnd - posStart; - if (len == 0) { - result = ""; - } else { - final char[] symbols = new char[len]; - LibSLRuntime.ArrayActions.copy(this.value, posStart, symbols, 0, len); - result = LibSLRuntime.toString(this.value); - } - } - return result; - } - - /** - * [SUBROUTINE] StringBuilderAutomaton::_asString() -> String - * Source: java/lang/StringBuilder.main.lsl:164 - */ - public String _asString() { - String result = null; - /* body */ { - final int len = this.count; - if (len == 0) { - result = ""; - } else { - if (len == this.value.length) { - result = LibSLRuntime.toString(this.value); - } else { - final char[] symbols = new char[len]; - LibSLRuntime.ArrayActions.copy(this.value, 0, symbols, 0, len); - result = LibSLRuntime.toString(this.value); - } - } - } - return result; - } - - /** - * [SUBROUTINE] StringBuilderAutomaton::_insertCharSequence(int, CharSequence, int, int) -> void - * Source: java/lang/StringBuilder.main.lsl:184 - */ - private void _insertCharSequence(int offset, CharSequence seq, int seqStart, int seqEnd) { - /* body */ { - if ((seqStart < 0) || (seqStart > seqEnd) || (seqEnd > seq.length()) || (offset > this.count)) { - throw new IndexOutOfBoundsException(); - } - final int avaiable = this.value.length - offset; - int len = seqEnd - seqStart; - if (len > avaiable) { - len = avaiable; - } - if (len > 0) { - final int avaiableForLeftovers = avaiable - len; - if (avaiableForLeftovers > 0) { - int rightLeftovers = this.count - offset; - if (rightLeftovers > avaiableForLeftovers) { - rightLeftovers = avaiableForLeftovers; - } - if (rightLeftovers > 0) { - final int rightIndex = offset + 1; - LibSLRuntime.ArrayActions.copy(this.value, rightIndex, this.value, rightIndex + len, rightLeftovers); - } - } - String str = null; - if ((seq instanceof String)) { - str = ((String) seq); - } else { - str = LibSLRuntime.toString(seq); - } - final char[] chars = str.toCharArray(); - LibSLRuntime.ArrayActions.copy(chars, seqStart, this.value, offset, len); - this.count += len; - } - } - } - - /** - * [SUBROUTINE] StringBuilderAutomaton::_deleteChars(int, int) -> void - * Source: java/lang/StringBuilder.main.lsl:225 - */ - private void _deleteChars(int start, int end) { - /* body */ { - if ((start < 0) || (start > end) || (end > this.count)) { - throw new IndexOutOfBoundsException(); - } - final int leftovers = this.count - end; - if (leftovers > 0) { - LibSLRuntime.ArrayActions.copy(this.value, end, this.value, start, leftovers); - } - this.count -= end - start; - } - } - - /** - * [FUNCTION] StringBuilderAutomaton::append(LSLStringBuilder, CharSequence) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:283 - */ - public StringBuilder append(CharSequence seq) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (seq == null) { - _appendCharSequence("null", 0, 4); - } else { - _appendCharSequence(seq, 0, seq.length()); - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::append(LSLStringBuilder, CharSequence, int, int) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:296 - */ - public StringBuilder append(CharSequence seq, int start, int end) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (seq == null) { - _appendCharSequence("null", start, end); - } else { - _appendCharSequence(seq, start, end); - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::append(LSLStringBuilder, Object) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:309 - */ - public StringBuilder append(Object obj) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (obj == null) { - _appendCharSequence("null", 0, 4); - } else { - final String seq = LibSLRuntime.toString(obj); - _appendCharSequence(seq, 0, seq.length()); - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::append(LSLStringBuilder, String) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:327 - */ - public StringBuilder append(String str) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (str == null) { - _appendCharSequence("null", 0, 4); - } else { - _appendCharSequence(str, 0, str.length()); - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::append(LSLStringBuilder, StringBuffer) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:340 - */ - public StringBuilder append(StringBuffer sb) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (sb == null) { - _appendCharSequence("null", 0, 4); - } else { - final String seq = LibSLRuntime.toString(sb); - _appendCharSequence(seq, 0, seq.length()); - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::append(LSLStringBuilder, boolean) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:358 - */ - public StringBuilder append(boolean x) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (x) { - _appendCharSequence("true", 0, 4); - } else { - _appendCharSequence("false", 0, 5); - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::append(LSLStringBuilder, char) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:371 - */ - public StringBuilder append(char x) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (this.count < this.value.length) { - value[this.count] = x; - this.count += 1; - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::append(LSLStringBuilder, array) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:385 - */ - public StringBuilder append(char[] str) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String seq = LibSLRuntime.toString(str); - _appendCharSequence(seq, 0, seq.length()); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::append(LSLStringBuilder, array, int, int) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:396 - */ - public StringBuilder append(char[] str, int offset, int len) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String seq = LibSLRuntime.toString(str); - _appendCharSequence(seq, offset, len); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::append(LSLStringBuilder, double) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:407 - */ - public StringBuilder append(double x) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String seq = LibSLRuntime.toString(x); - _appendCharSequence(seq, 0, seq.length()); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::append(LSLStringBuilder, float) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:418 - */ - public StringBuilder append(float x) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String seq = LibSLRuntime.toString(x); - _appendCharSequence(seq, 0, seq.length()); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::append(LSLStringBuilder, int) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:429 - */ - public StringBuilder append(int x) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String seq = LibSLRuntime.toString(x); - _appendCharSequence(seq, 0, seq.length()); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::append(LSLStringBuilder, long) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:440 - */ - public StringBuilder append(long x) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String seq = LibSLRuntime.toString(x); - _appendCharSequence(seq, 0, seq.length()); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::appendCodePoint(LSLStringBuilder, int) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:451 - */ - public StringBuilder appendCodePoint(int codePoint) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final int cnt = this.count; - final int len = this.value.length; - if (Character.isBmpCodePoint(codePoint)) { - if ((cnt + 1) <= len) { - value[cnt] = ((char) codePoint); - this.count = cnt + 1; - } - } else { - if (Character.isValidCodePoint(codePoint)) { - if ((cnt + 2) <= len) { - value[cnt + 1] = Character.lowSurrogate(codePoint); - value[cnt] = Character.highSurrogate(codePoint); - this.count = cnt + 2; - } - } else { - throw new IllegalArgumentException(); - } - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::capacity(LSLStringBuilder) -> int - * Source: java/lang/StringBuilder.main.lsl:488 - */ - public int capacity() { - int result = 0; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - result = this.value.length; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::charAt(LSLStringBuilder, int) -> char - * Source: java/lang/StringBuilder.main.lsl:496 - */ - public char charAt(int index) { - char result = '?'; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if ((index < 0) || (index >= this.count)) { - throw new StringIndexOutOfBoundsException(); - } - result = value[index]; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::chars(LSLStringBuilder) -> IntStream - * Source: java/lang/StringBuilder.main.lsl:508 - */ - public IntStream chars() { - IntStream result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final int len = this.count; - final int[] intValues = new int[len]; - int i = 0; - for (i = 0; i < len; i += 1) { - intValues[i] = ((int) value[i]); - } - ; - result = (IntStreamLSL) ((Object) new generated.java.util.stream.IntStreamLSL((Void) null, - /* state = */ generated.java.util.stream.IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ intValues, - /* length = */ len, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::codePointAt(LSLStringBuilder, int) -> int - * Source: java/lang/StringBuilder.main.lsl:534 - */ - public int codePointAt(int index) { - int result = 0; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if ((index < 0) || (index >= this.count)) { - throw new StringIndexOutOfBoundsException(index); - } - result = Character.codePointAt(this.value, index, this.count); - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::codePointBefore(LSLStringBuilder, int) -> int - * Source: java/lang/StringBuilder.main.lsl:545 - */ - public int codePointBefore(int index) { - int result = 0; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final int i = index - 1; - if ((i < 0) || (i >= this.count)) { - throw new StringIndexOutOfBoundsException(index); - } - result = Character.codePointBefore(this.value, index, 0); - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::codePointCount(LSLStringBuilder, int, int) -> int - * Source: java/lang/StringBuilder.main.lsl:557 - */ - public int codePointCount(int beginIndex, int endIndex) { - int result = 0; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if ((beginIndex < 0) || (beginIndex > endIndex) || (endIndex > this.count)) { - throw new IndexOutOfBoundsException(); - } - result = Character.codePointCount(this.value, beginIndex, endIndex - beginIndex); - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::codePoints(LSLStringBuilder) -> IntStream - * Source: java/lang/StringBuilder.main.lsl:569 - */ - public IntStream codePoints() { - IntStream result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final int len = this.count; - final int[] intValues = new int[len]; - int i = 0; - for (i = 0; i < len; i += 1) { - intValues[i] = ((int) value[i]); - } - ; - result = (IntStreamLSL) ((Object) new generated.java.util.stream.IntStreamLSL((Void) null, - /* state = */ generated.java.util.stream.IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ intValues, - /* length = */ len, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::compareTo(LSLStringBuilder, LSLStringBuilder) -> int - * Source: java/lang/StringBuilder.main.lsl:590 - */ - public int compareTo(StringBuilder another) { - int result = 0; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (another == this) { - result = 0; - } else { - final String thisString = _asString(); - final String anotherString = ((StringBuilder) ((Object) another))._asString(); - result = thisString.compareTo(anotherString); - } - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::delete(LSLStringBuilder, int, int) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:608 - */ - public StringBuilder delete(int start, int end) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - _deleteChars(start, end); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::deleteCharAt(LSLStringBuilder, int) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:618 - */ - public StringBuilder deleteCharAt(int index) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - _deleteChars(index, index + 1); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::ensureCapacity(LSLStringBuilder, int) -> void - * Source: java/lang/StringBuilder.main.lsl:628 - */ - public void ensureCapacity(int minimumCapacity) { - /* body */ { - Engine.assume(true); - } - } - - /** - * [FUNCTION] StringBuilderAutomaton::getChars(LSLStringBuilder, int, int, array, int) -> void - * Source: java/lang/StringBuilder.main.lsl:635 - */ - public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) { - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if ((srcBegin < 0) || (srcBegin > srcEnd) || (srcEnd > this.count)) { - throw new StringIndexOutOfBoundsException(); - } - final int len = srcEnd - srcBegin; - if (dst == null) { - throw new NullPointerException(); - } - if ((dstBegin < 0) || ((dstBegin + len) > dst.length)) { - throw new IndexOutOfBoundsException(); - } - if (len > 0) { - LibSLRuntime.ArrayActions.copy(this.value, srcBegin, dst, dstBegin, len); - } - } - } - - /** - * [FUNCTION] StringBuilderAutomaton::getValue(LSLStringBuilder) -> array - * Source: java/lang/StringBuilder.main.lsl:656 - */ - public char[] getValue() { - char[] result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - result = this.value; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::indexOf(LSLStringBuilder, String) -> int - * Source: java/lang/StringBuilder.main.lsl:664 - */ - public int indexOf(String str) { - int result = 0; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - result = _asString().indexOf(str, 0); - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::indexOf(LSLStringBuilder, String, int) -> int - * Source: java/lang/StringBuilder.main.lsl:673 - */ - public int indexOf(String str, int fromIndex) { - int result = 0; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - result = _asString().indexOf(str, fromIndex); - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::insert(LSLStringBuilder, int, CharSequence) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:682 - */ - public StringBuilder insert(int dstOffset, CharSequence s) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (s == null) { - _insertCharSequence(dstOffset, "null", 0, 4); - } else { - _insertCharSequence(dstOffset, s, 0, s.length()); - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::insert(LSLStringBuilder, int, CharSequence, int, int) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:695 - */ - public StringBuilder insert(int dstOffset, CharSequence s, int start, int end) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (s == null) { - _insertCharSequence(dstOffset, "null", start, end); - } else { - _insertCharSequence(dstOffset, s, start, end); - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::insert(LSLStringBuilder, int, Object) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:708 - */ - public StringBuilder insert(int dstOffset, Object obj) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (obj == null) { - _insertCharSequence(dstOffset, "null", 0, 4); - } else { - final String s = LibSLRuntime.toString(obj); - _insertCharSequence(dstOffset, s, 0, s.length()); - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::insert(LSLStringBuilder, int, String) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:726 - */ - public StringBuilder insert(int dstOffset, String s) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (s == null) { - _insertCharSequence(dstOffset, "null", 0, 4); - } else { - _insertCharSequence(dstOffset, s, 0, s.length()); - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::insert(LSLStringBuilder, int, boolean) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:739 - */ - public StringBuilder insert(int dstOffset, boolean x) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String s = LibSLRuntime.toString(x); - _insertCharSequence(dstOffset, s, 0, s.length()); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::insert(LSLStringBuilder, int, char) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:750 - */ - public StringBuilder insert(int dstOffset, char x) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String s = LibSLRuntime.toString(x); - _insertCharSequence(dstOffset, s, 0, 1); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::insert(LSLStringBuilder, int, array) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:761 - */ - public StringBuilder insert(int dstOffset, char[] x) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String s = LibSLRuntime.toString(x); - _insertCharSequence(dstOffset, s, 0, s.length()); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::insert(LSLStringBuilder, int, array, int, int) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:772 - */ - public StringBuilder insert(int index, char[] str, int offset, int len) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final char[] arr = new char[len]; - LibSLRuntime.ArrayActions.copy(str, offset, arr, 0, len); - final String s = LibSLRuntime.toString(arr); - _insertCharSequence(index, s, 0, len); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::insert(LSLStringBuilder, int, double) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:786 - */ - public StringBuilder insert(int dstOffset, double x) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String s = LibSLRuntime.toString(x); - _insertCharSequence(dstOffset, s, 0, s.length()); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::insert(LSLStringBuilder, int, float) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:797 - */ - public StringBuilder insert(int dstOffset, float x) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String s = LibSLRuntime.toString(x); - _insertCharSequence(dstOffset, s, 0, s.length()); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::insert(LSLStringBuilder, int, int) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:808 - */ - public StringBuilder insert(int dstOffset, int x) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String s = LibSLRuntime.toString(x); - _insertCharSequence(dstOffset, s, 0, s.length()); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::insert(LSLStringBuilder, int, long) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:819 - */ - public StringBuilder insert(int dstOffset, long x) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final String s = LibSLRuntime.toString(x); - _insertCharSequence(dstOffset, s, 0, s.length()); - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::lastIndexOf(LSLStringBuilder, String) -> int - * Source: java/lang/StringBuilder.main.lsl:830 - */ - public int lastIndexOf(String str) { - int result = 0; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - result = _asString().lastIndexOf(str, this.count); - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::lastIndexOf(LSLStringBuilder, String, int) -> int - * Source: java/lang/StringBuilder.main.lsl:839 - */ - public int lastIndexOf(String str, int fromIndex) { - int result = 0; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - result = _asString().lastIndexOf(str, fromIndex); - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::length(LSLStringBuilder) -> int - * Source: java/lang/StringBuilder.main.lsl:848 - */ - public int length() { - int result = 0; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - result = this.count; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::offsetByCodePoints(LSLStringBuilder, int, int) -> int - * Source: java/lang/StringBuilder.main.lsl:856 - */ - public int offsetByCodePoints(int index, int codePointOffset) { - int result = 0; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if ((index < 0) || (index > this.count)) { - throw new IndexOutOfBoundsException(); - } - result = Character.offsetByCodePoints(this.value, 0, this.count, index, codePointOffset); - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::replace(LSLStringBuilder, int, int, String) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:867 - */ - public StringBuilder replace(int start, int end, String s) { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - _deleteChars(start, end); - if (s == null) { - _insertCharSequence(start, "null", 0, 4); - } else { - _insertCharSequence(start, s, 0, s.length()); - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::reverse(LSLStringBuilder) -> LSLStringBuilder - * Source: java/lang/StringBuilder.main.lsl:882 - */ - public StringBuilder reverse() { - StringBuilder result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if (this.count != 0) { - boolean hasSurrogates = false; - final int n = this.count - 1; - int j = 0; - for (j = (n - 1) >> 1; j > -1; j += -1) { - int k = n - j; - char cj = value[j]; - char ck = value[k]; - value[j] = ck; - value[k] = cj; - if (Character.isSurrogate(cj) || Character.isSurrogate(ck)) { - hasSurrogates = true; - } - } - ; - if (hasSurrogates) { - int i = 0; - for (i = 0; i < n; i += 1) { - char c2 = value[i]; - if (Character.isLowSurrogate(c2)) { - char c1 = value[i + 1]; - if (Character.isHighSurrogate(c1)) { - value[i] = c1; - i += 1; - value[i] = c2; - } - } - } - ; - } - } - result = this; - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::setCharAt(LSLStringBuilder, int, char) -> void - * Source: java/lang/StringBuilder.main.lsl:944 - */ - public void setCharAt(int index, char x) { - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if ((index < 0) || (index >= this.count)) { - throw new StringIndexOutOfBoundsException(); - } - value[index] = x; - } - } - - /** - * [FUNCTION] StringBuilderAutomaton::setLength(LSLStringBuilder, int) -> void - * Source: java/lang/StringBuilder.main.lsl:955 - */ - public void setLength(int newLength) { - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - final int maxLength = this.value.length; - if (newLength > maxLength) { - newLength = maxLength; - } - if (newLength < 0) { - throw new StringIndexOutOfBoundsException(); - } else { - if (newLength < this.count) { - this.count = newLength; - } else { - if (newLength > this.count) { - LibSLRuntime.ArrayActions.fillRange(this.value, this.count, newLength, ((char) 0)); - this.count = newLength; - } - } - } - } - } - - /** - * [FUNCTION] StringBuilderAutomaton::subSequence(LSLStringBuilder, int, int) -> CharSequence - * Source: java/lang/StringBuilder.main.lsl:980 - */ - public CharSequence subSequence(int start, int end) { - CharSequence result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if ((start < 0) || (start > end) || (end > this.count)) { - throw new StringIndexOutOfBoundsException(); - } - result = _asString(start, end); - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::substring(LSLStringBuilder, int) -> String - * Source: java/lang/StringBuilder.main.lsl:991 - */ - public String substring(int start) { - String result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if ((start < 0) || (start > this.count)) { - throw new StringIndexOutOfBoundsException(); - } - result = _asString(start, this.count); - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::substring(LSLStringBuilder, int, int) -> String - * Source: java/lang/StringBuilder.main.lsl:1002 - */ - public String substring(int start, int end) { - String result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - if ((start < 0) || (start > end) || (end > this.count)) { - throw new StringIndexOutOfBoundsException(); - } - result = _asString(start, end); - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::toString(LSLStringBuilder) -> String - * Source: java/lang/StringBuilder.main.lsl:1013 - */ - public String toString() { - String result = null; - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - result = _asString(); - } - return result; - } - - /** - * [FUNCTION] StringBuilderAutomaton::trimToSize(LSLStringBuilder) -> void - * Source: java/lang/StringBuilder.main.lsl:1021 - */ - public void trimToSize() { - /* body */ { - Engine.assume(this.value != null); - Engine.assume(this.value.length <= STRINGBUILDER_LENGTH_MAX); - Engine.assume(this.count <= this.value.length); - Engine.assume(this.count >= 0); - } - } - - /** - * [FUNCTION] StringBuilderAutomaton::writeObject(LSLStringBuilder, ObjectOutputStream) -> void - * Source: java/lang/StringBuilder.main.lsl:1034 - */ - private void writeObject(ObjectOutputStream s) throws java.io.IOException { - /* body */ { - LibSLRuntime.not_implemented(/* no serialization support yet */); - } - } - - /** - * [FUNCTION] StringBuilderAutomaton::readObject(LSLStringBuilder, ObjectInputStream) -> void - * Source: java/lang/StringBuilder.main.lsl:1042 - */ - private void readObject(ObjectInputStream s) throws java.io.IOException, - java.lang.ClassNotFoundException { - /* body */ { - LibSLRuntime.not_implemented(/* no serialization support yet */); - } - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(StringBuilder.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/lang/StringBuilderImpl.java b/approximations/src/main/java/generated/java/lang/StringBuilderImpl.java new file mode 100644 index 00000000..98d52929 --- /dev/null +++ b/approximations/src/main/java/generated/java/lang/StringBuilderImpl.java @@ -0,0 +1,654 @@ +package generated.java.lang; + +import java.io.Serial; +import java.io.Serializable; +import java.lang.CharSequence; +import java.lang.Character; +import java.lang.Comparable; +import java.lang.IllegalArgumentException; +import java.lang.IndexOutOfBoundsException; +import java.lang.NegativeArraySizeException; +import java.lang.NullPointerException; +import java.lang.Object; +import java.lang.OutOfMemoryError; +import java.lang.String; +import java.lang.StringBuffer; +import java.lang.StringIndexOutOfBoundsException; +import java.util.stream.IntStream; + +import generated.java.util.stream.IntStreamImpl; +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +@SuppressWarnings("unused") +@Approximate(java.lang.StringBuilder.class) +public final class StringBuilderImpl implements Serializable, Comparable, CharSequence { + // TODO: unify with StringBufferImpl: create approximation on 'AbstractStringBuilder' (it's private) + + @Serial + private static final long serialVersionUID = 4383685877147921099L; + + private static final int STRING_BUILDER_LENGTH_MAX = 50; + + static { + Engine.assume(true); + } + + public char[] value; + + public int count = 0; + + public StringBuilderImpl(char[] value, int count) { + this.value = value; + this.count = count; + } + + public StringBuilderImpl() { + this(new char[STRING_BUILDER_LENGTH_MAX], 0); + } + + public StringBuilderImpl(CharSequence seq) { + if (seq == null) + throw new NullPointerException(); + this.value = new char[STRING_BUILDER_LENGTH_MAX]; + _appendCharSequence(seq, 0, seq.length()); + } + + public StringBuilderImpl(String str) { + if (str == null) + throw new NullPointerException(); + this.value = new char[STRING_BUILDER_LENGTH_MAX]; + _appendCharSequence(str, 0, str.length()); + } + + public StringBuilderImpl(int cap) { + if (cap < 0) + throw new NegativeArraySizeException(); + if (cap > 1073741823) + throw new OutOfMemoryError("Requested array size exceeds VM limit"); + this.value = new char[STRING_BUILDER_LENGTH_MAX]; + } + + private void _appendCharSequence(CharSequence seq, int seqStart, int seqEnd) { + if (seqStart < 0 || seqStart > seqEnd || seqEnd > seq.length()) + throw new IndexOutOfBoundsException(); + int available = this.value.length - this.count; + int len = seqEnd - seqStart; + if (len > available) + len = available; + if (len <= 0) + return; + + String str; + if (seq instanceof String) { + str = (String) seq; + } else { + str = LibSLRuntime.toString(seq); + } + char[] chars = str.toCharArray(); + LibSLRuntime.ArrayActions.copy(chars, seqStart, this.value, this.count, len); + this.count += len; + } + + private String _asString(int posStart, int posEnd) { + int len = posEnd - posStart; + if (len == 0) + return ""; + + char[] symbols = new char[len]; + LibSLRuntime.ArrayActions.copy(this.value, posStart, symbols, 0, len); + return LibSLRuntime.toString(this.value); + } + + public String _asString() { + int len = this.count; + if (len == 0) + return ""; + + if (len == this.value.length) + return LibSLRuntime.toString(this.value); + + char[] symbols = new char[len]; + LibSLRuntime.ArrayActions.copy(this.value, 0, symbols, 0, len); + return LibSLRuntime.toString(this.value); + } + + private void _insertCharSequence(int offset, CharSequence seq, int seqStart, int seqEnd) { + if (seqStart < 0 || seqStart > seqEnd || seqEnd > seq.length() || offset > this.count) + throw new IndexOutOfBoundsException(); + + int available = this.value.length - offset; + int len = seqEnd - seqStart; + if (len > available) + len = available; + + if (len <= 0) + return; + + int availableForLeftovers = available - len; + if (availableForLeftovers > 0) { + int rightLeftovers = this.count - offset; + if (rightLeftovers > availableForLeftovers) { + rightLeftovers = availableForLeftovers; + } + if (rightLeftovers > 0) { + int rightIndex = offset + 1; + LibSLRuntime.ArrayActions.copy(this.value, rightIndex, this.value, rightIndex + len, rightLeftovers); + } + } + String str; + if (seq instanceof String) { + str = (String) seq; + } else { + str = LibSLRuntime.toString(seq); + } + char[] chars = str.toCharArray(); + LibSLRuntime.ArrayActions.copy(chars, seqStart, this.value, offset, len); + this.count += len; + } + + private void _deleteChars(int start, int end) { + if (start < 0 || start > end || end > this.count) + throw new IndexOutOfBoundsException(); + + int leftovers = this.count - end; + if (leftovers > 0) + LibSLRuntime.ArrayActions.copy(this.value, end, this.value, start, leftovers); + this.count -= end - start; + } + + @SuppressWarnings("DataFlowIssue") + private void _assumeInvariants() { + Engine.assume(this.value != null); + Engine.assume(this.value.length <= STRING_BUILDER_LENGTH_MAX); + Engine.assume(this.count <= this.value.length); + Engine.assume(this.count >= 0); + } + + public StringBuilderImpl append(CharSequence seq) { + _assumeInvariants(); + if (seq == null) { + _appendCharSequence("null", 0, 4); + } else { + _appendCharSequence(seq, 0, seq.length()); + } + + return this; + } + + @SuppressWarnings("ReplaceNullCheck") + public StringBuilderImpl append(CharSequence seq, int start, int end) { + _assumeInvariants(); + if (seq == null) { + _appendCharSequence("null", start, end); + } else { + _appendCharSequence(seq, start, end); + } + return this; + } + + public StringBuilderImpl append(Object obj) { + _assumeInvariants(); + if (obj == null) { + _appendCharSequence("null", 0, 4); + } else { + String seq = LibSLRuntime.toString(obj); + _appendCharSequence(seq, 0, seq.length()); + } + return this; + } + + public StringBuilderImpl append(String str) { + _assumeInvariants(); + if (str == null) { + _appendCharSequence("null", 0, 4); + } else { + _appendCharSequence(str, 0, str.length()); + } + return this; + } + + public StringBuilderImpl append(StringBuffer sb) { + _assumeInvariants(); + if (sb == null) { + _appendCharSequence("null", 0, 4); + } else { + String seq = LibSLRuntime.toString(sb); + _appendCharSequence(seq, 0, seq.length()); + } + return this; + } + + public StringBuilderImpl append(boolean x) { + _assumeInvariants(); + if (x) { + _appendCharSequence("true", 0, 4); + } else { + _appendCharSequence("false", 0, 5); + } + return this; + } + + public StringBuilderImpl append(char x) { + _assumeInvariants(); + if (this.count < this.value.length) { + value[this.count] = x; + this.count++; + } + return this; + } + + public StringBuilderImpl append(char[] str) { + _assumeInvariants(); + String seq = LibSLRuntime.toString(str); + _appendCharSequence(seq, 0, seq.length()); + return this; + } + + public StringBuilderImpl append(char[] str, int offset, int len) { + _assumeInvariants(); + String seq = LibSLRuntime.toString(str); + _appendCharSequence(seq, offset, len); + return this; + } + + public StringBuilderImpl append(double x) { + _assumeInvariants(); + String seq = LibSLRuntime.toString(x); + _appendCharSequence(seq, 0, seq.length()); + return this; + } + + public StringBuilderImpl append(float x) { + _assumeInvariants(); + String seq = LibSLRuntime.toString(x); + _appendCharSequence(seq, 0, seq.length()); + return this; + } + + public StringBuilderImpl append(int x) { + _assumeInvariants(); + String seq = LibSLRuntime.toString(x); + _appendCharSequence(seq, 0, seq.length()); + return this; + } + + public StringBuilderImpl append(long x) { + _assumeInvariants(); + String seq = LibSLRuntime.toString(x); + _appendCharSequence(seq, 0, seq.length()); + return this; + } + + public StringBuilderImpl appendCodePoint(int codePoint) { + _assumeInvariants(); + int cnt = this.count; + int len = this.value.length; + if (Character.isBmpCodePoint(codePoint)) { + if (cnt + 1 <= len) { + value[cnt] = ((char) codePoint); + this.count = cnt + 1; + } + } else { + if (Character.isValidCodePoint(codePoint)) { + if (cnt + 2 <= len) { + value[cnt + 1] = Character.lowSurrogate(codePoint); + value[cnt] = Character.highSurrogate(codePoint); + this.count = cnt + 2; + } + } else { + throw new IllegalArgumentException(); + } + } + return this; + } + + public int capacity() { + _assumeInvariants(); + return this.value.length; + } + + public char charAt(int index) { + _assumeInvariants(); + if (index < 0 || index >= this.count) + throw new StringIndexOutOfBoundsException(); + + return value[index]; + } + + @NotNull + public IntStream chars() { + _assumeInvariants(); + int len = this.count; + int[] intValues = new int[len]; + for (int i = 0; i < len; i++) { + intValues[i] = value[i]; + } + + return new IntStreamImpl(intValues); + } + + public int codePointAt(int index) { + _assumeInvariants(); + if (index < 0 || index >= this.count) + throw new StringIndexOutOfBoundsException(index); + + return Character.codePointAt(this.value, index, this.count); + } + + public int codePointBefore(int index) { + _assumeInvariants(); + int i = index - 1; + if (i < 0 || i >= this.count) + throw new StringIndexOutOfBoundsException(index); + + return Character.codePointBefore(this.value, index, 0); + } + + public int codePointCount(int beginIndex, int endIndex) { + _assumeInvariants(); + if (beginIndex < 0 || beginIndex > endIndex || endIndex > this.count) + throw new IndexOutOfBoundsException(); + + return Character.codePointCount(this.value, beginIndex, endIndex - beginIndex); + } + + @NotNull + public IntStream codePoints() { + _assumeInvariants(); + int len = this.count; + int[] intValues = new int[len]; + for (int i = 0; i < len; i++) { + intValues[i] = value[i]; + } + return new IntStreamImpl(intValues); + } + + public int compareTo(@NotNull StringBuilderImpl another) { + _assumeInvariants(); + if (another == this) + return 0; + + String thisString = _asString(); + String anotherString = another._asString(); + return thisString.compareTo(anotherString); + } + + public StringBuilderImpl delete(int start, int end) { + _assumeInvariants(); + _deleteChars(start, end); + return this; + } + + public StringBuilderImpl deleteCharAt(int index) { + _assumeInvariants(); + _deleteChars(index, index + 1); + return this; + } + + public void ensureCapacity(int minimumCapacity) { + Engine.assume(true); + } + + public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) { + _assumeInvariants(); + if (srcBegin < 0 || srcBegin > srcEnd || srcEnd > this.count) + throw new StringIndexOutOfBoundsException(); + int len = srcEnd - srcBegin; + if (dst == null) + throw new NullPointerException(); + if (dstBegin < 0 || dstBegin + len > dst.length) + throw new IndexOutOfBoundsException(); + if (len > 0) + LibSLRuntime.ArrayActions.copy(this.value, srcBegin, dst, dstBegin, len); + } + + public char[] getValue() { + _assumeInvariants(); + return this.value; + } + + public int indexOf(String str) { + _assumeInvariants(); + return _asString().indexOf(str); + } + + public int indexOf(String str, int fromIndex) { + _assumeInvariants(); + return _asString().indexOf(str, fromIndex); + } + + public StringBuilderImpl insert(int dstOffset, CharSequence s) { + _assumeInvariants(); + if (s == null) { + _insertCharSequence(dstOffset, "null", 0, 4); + } else { + _insertCharSequence(dstOffset, s, 0, s.length()); + } + return this; + } + + @SuppressWarnings("ReplaceNullCheck") + public StringBuilderImpl insert(int dstOffset, CharSequence s, int start, int end) { + _assumeInvariants(); + if (s == null) { + _insertCharSequence(dstOffset, "null", start, end); + } else { + _insertCharSequence(dstOffset, s, start, end); + } + return this; + } + + public StringBuilderImpl insert(int dstOffset, Object obj) { + _assumeInvariants(); + if (obj == null) { + _insertCharSequence(dstOffset, "null", 0, 4); + } else { + String s = LibSLRuntime.toString(obj); + _insertCharSequence(dstOffset, s, 0, s.length()); + } + return this; + } + + public StringBuilderImpl insert(int dstOffset, String s) { + _assumeInvariants(); + if (s == null) { + _insertCharSequence(dstOffset, "null", 0, 4); + } else { + _insertCharSequence(dstOffset, s, 0, s.length()); + } + return this; + } + + public StringBuilderImpl insert(int dstOffset, boolean x) { + _assumeInvariants(); + String s = LibSLRuntime.toString(x); + _insertCharSequence(dstOffset, s, 0, s.length()); + return this; + } + + public StringBuilderImpl insert(int dstOffset, char x) { + _assumeInvariants(); + String s = LibSLRuntime.toString(x); + _insertCharSequence(dstOffset, s, 0, 1); + return this; + } + + public StringBuilderImpl insert(int dstOffset, char[] x) { + _assumeInvariants(); + String s = LibSLRuntime.toString(x); + _insertCharSequence(dstOffset, s, 0, s.length()); + return this; + } + + public StringBuilderImpl insert(int index, char[] str, int offset, int len) { + _assumeInvariants(); + char[] arr = new char[len]; + LibSLRuntime.ArrayActions.copy(str, offset, arr, 0, len); + String s = LibSLRuntime.toString(arr); + _insertCharSequence(index, s, 0, len); + return this; + } + + public StringBuilderImpl insert(int dstOffset, double x) { + _assumeInvariants(); + String s = LibSLRuntime.toString(x); + _insertCharSequence(dstOffset, s, 0, s.length()); + return this; + } + + public StringBuilderImpl insert(int dstOffset, float x) { + _assumeInvariants(); + String s = LibSLRuntime.toString(x); + _insertCharSequence(dstOffset, s, 0, s.length()); + return this; + } + + public StringBuilderImpl insert(int dstOffset, int x) { + _assumeInvariants(); + String s = LibSLRuntime.toString(x); + _insertCharSequence(dstOffset, s, 0, s.length()); + return this; + } + + public StringBuilderImpl insert(int dstOffset, long x) { + _assumeInvariants(); + String s = LibSLRuntime.toString(x); + _insertCharSequence(dstOffset, s, 0, s.length()); + return this; + } + + public int lastIndexOf(String str) { + _assumeInvariants(); + return _asString().lastIndexOf(str, this.count); + } + + public int lastIndexOf(String str, int fromIndex) { + _assumeInvariants(); + return _asString().lastIndexOf(str, fromIndex); + } + + public int length() { + _assumeInvariants(); + return this.count; + } + + public int offsetByCodePoints(int index, int codePointOffset) { + _assumeInvariants(); + if (index < 0 || index > this.count) + throw new IndexOutOfBoundsException(); + + return Character.offsetByCodePoints(this.value, 0, this.count, index, codePointOffset); + } + + public StringBuilderImpl replace(int start, int end, String s) { + _assumeInvariants(); + _deleteChars(start, end); + if (s == null) { + _insertCharSequence(start, "null", 0, 4); + } else { + _insertCharSequence(start, s, 0, s.length()); + } + return this; + } + + public StringBuilderImpl reverse() { + _assumeInvariants(); + if (this.count == 0) + return this; + + boolean hasSurrogates = false; + int n = this.count - 1; + for (int i = (n - 1) >> 1; i > -1; i--) { + int k = n - i; + char cj = value[i]; + char ck = value[k]; + value[i] = ck; + value[k] = cj; + if (Character.isSurrogate(cj) || Character.isSurrogate(ck)) { + hasSurrogates = true; + } + } + if (!hasSurrogates) + return this; + + for (int i = 0; i < n; i++) { + char c2 = value[i]; + if (Character.isLowSurrogate(c2)) { + char c1 = value[i + 1]; + if (Character.isHighSurrogate(c1)) { + value[i] = c1; + i++; + value[i] = c2; + } + } + } + + return this; + } + + public void setCharAt(int index, char x) { + _assumeInvariants(); + if (index < 0 || index >= this.count) + throw new StringIndexOutOfBoundsException(); + + value[index] = x; + } + + public void setLength(int newLength) { + _assumeInvariants(); + int maxLength = this.value.length; + if (newLength > maxLength) + newLength = maxLength; + + if (newLength < 0) + throw new StringIndexOutOfBoundsException(); + + if (newLength < this.count) { + this.count = newLength; + return; + } + + if (newLength > this.count) { + LibSLRuntime.ArrayActions.fillRange(this.value, this.count, newLength, ((char) 0)); + this.count = newLength; + } + } + + @NotNull + public CharSequence subSequence(int start, int end) { + _assumeInvariants(); + if (start < 0 || start > end || end > this.count) + throw new StringIndexOutOfBoundsException(); + + return _asString(start, end); + } + + public String substring(int start) { + _assumeInvariants(); + if (start < 0 || start > this.count) + throw new StringIndexOutOfBoundsException(); + + return _asString(start, this.count); + } + + public String substring(int start, int end) { + _assumeInvariants(); + if (start < 0 || start > end || end > this.count) + throw new StringIndexOutOfBoundsException(); + + return _asString(start, end); + } + + @NotNull + public String toString() { + _assumeInvariants(); + return _asString(); + } + + public void trimToSize() { + _assumeInvariants(); + } +} diff --git a/approximations/src/main/java/generated/java/lang/StringImpl.java b/approximations/src/main/java/generated/java/lang/StringImpl.java new file mode 100644 index 00000000..5ec99d3b --- /dev/null +++ b/approximations/src/main/java/generated/java/lang/StringImpl.java @@ -0,0 +1,153 @@ +package generated.java.lang; + +import java.io.Serializable; +import java.lang.Object; +import java.lang.StringIndexOutOfBoundsException; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +@SuppressWarnings("unused") +@Approximate(java.lang.String.class) +public class StringImpl implements Serializable { + + @java.io.Serial + private static final long serialVersionUID = -6849794470754667710L; + + private static final int STRING_LENGTH_MAX = 50; + + public byte[] value; + + public int length; + + public StringImpl(byte[] value, int length) { + this.value = value; + this.length = length; + } + +// @SuppressWarnings("ConstantValue") +// public StringImpl(char[] value, int offset, int count) { +// if (value == null) +// throw new NullPointerException(); +// +// int size = value.length; +// if (length < 0 || offset < 0 || size < 0 || size > length - offset) +// throw new IndexOutOfBoundsException(); +// +// char[] newValue = new char[count]; +// LibSLRuntime.ArrayActions.copy(value, offset, newValue, 0, count); +// +// } + + public StringImpl() { + this(new byte[0], 0); + } + + public StringImpl(StringImpl original) { + this(original.value, original.length); + } + + public StringImpl(byte[] bytes) { + int len = bytes.length; + this.length = len; + this.value = new byte[len]; + LibSLRuntime.ArrayActions.copy(bytes, 0, this.value, 0, len); + } + + public static java.lang.String copyValueOf(char[] data) { + return LibSLRuntime.toString(data); + } + + public static java.lang.String copyValueOf(char[] data, int offset, int count) { + char[] segment = new char[count]; + LibSLRuntime.ArrayActions.copy(data, offset, segment, 0, count); + return LibSLRuntime.toString(segment); + } + + public static java.lang.String valueOf(Object x) { + return LibSLRuntime.toString(x); + } + + public static java.lang.String valueOf(boolean x) { + return LibSLRuntime.toString(x); + } + + public static java.lang.String valueOf(char x) { + return LibSLRuntime.toString(x); + } + + public static java.lang.String valueOf(char[] data) { + return LibSLRuntime.toString(data); + } + + public static java.lang.String valueOf(char[] data, int offset, int count) { + char[] segment = new char[count]; + LibSLRuntime.ArrayActions.copy(data, offset, segment, 0, count); + return LibSLRuntime.toString(segment); + } + + public static java.lang.String valueOf(double x) { + return LibSLRuntime.toString(x); + } + + public static java.lang.String valueOf(float x) { + return LibSLRuntime.toString(x); + } + + public static java.lang.String valueOf(int x) { + return LibSLRuntime.toString(x); + } + + public static java.lang.String valueOf(long x) { + return LibSLRuntime.toString(x); + } + + @SuppressWarnings("DataFlowIssue") + public StringImpl concat(StringImpl str) { + Engine.assume(this.value != null); + Engine.assume(this.value.length <= STRING_LENGTH_MAX); + Engine.assume(this.length == this.value.length); + byte[] otherVal = str.value; + int otherLen = otherVal.length; + if (otherLen == 0) + return this; + + int newLength = this.length + otherLen; + byte[] newValue = new byte[newLength]; + LibSLRuntime.ArrayActions.copy(this.value, 0, newValue, 0, this.length); + LibSLRuntime.ArrayActions.copy(otherVal, 0, newValue, this.length, otherLen); + return new StringImpl(newValue, newLength); + } + + @SuppressWarnings("DataFlowIssue") + public byte[] getBytes() { + Engine.assume(this.value != null); + Engine.assume(this.value.length <= STRING_LENGTH_MAX); + Engine.assume(this.length == this.value.length); + return this.value; + } + + @SuppressWarnings("DataFlowIssue") + public void getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin) { + if (srcBegin < 0) + throw new StringIndexOutOfBoundsException(srcBegin); + if (this.length < srcEnd) + throw new StringIndexOutOfBoundsException(srcEnd); + int count = srcEnd - srcBegin; + if (count < 0) + throw new StringIndexOutOfBoundsException(count); + Engine.assume(this.value != null); + Engine.assume(this.value.length <= STRING_LENGTH_MAX); + Engine.assume(this.length == this.value.length); + LibSLRuntime.ArrayActions.copy(this.value, srcBegin, dst, dstBegin, count); + } + + public boolean isEmpty() { + return this.length == 0; + } + + public int length() { + return this.length; + } +} diff --git a/approximations/src/main/java/generated/java/lang/System.java b/approximations/src/main/java/generated/java/lang/System.java deleted file mode 100644 index 8f00e51a..00000000 --- a/approximations/src/main/java/generated/java/lang/System.java +++ /dev/null @@ -1,588 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/lang/System.lsl:56 -// - java/lang/System.main.lsl:33 -// -package generated.java.lang; - -import generated.runtime.LibSLGlobals; -import java.io.Console; -import java.io.InputStream; -import java.io.PrintStream; -import java.lang.IllegalArgumentException; -import java.lang.Integer; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SecurityException; -import java.lang.SecurityManager; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.UnsatisfiedLinkError; -import java.lang.Void; -import java.util.Properties; -import jdk.internal.misc.VM; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; -import stub.libsl.utils.SymbolicInputStream; - -/** - * SystemAutomaton for LSLSystem ~> java.lang.System - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.lang.System.class) -public final class System implements LibSLRuntime.Automaton { - private static final LibSLRuntime.Map propsMap = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - - private static volatile SecurityManager security = null; - - private static Properties props = null; - - private static Console console = null; - - public static InputStream in = null; - - public static PrintStream out = null; - - public static PrintStream err = null; - - private static final long NANOTIME_BEGINNING_OF_TIME = 1000L; - - private static final long NANOTIME_WARP_MAX = 1000L; - - private static final LibSLRuntime.Map identityHashCodeMap = new LibSLRuntime.Map<>(new LibSLRuntime.IdentityMapContainer<>()); - - static { - /* SystemAutomaton::() */ { - initPhase1(); - initPhase2(); - initPhase3(); - } - } - - @LibSLRuntime.AutomatonConstructor - public System(Void __$lsl_token, final byte p0) { - } - - @LibSLRuntime.AutomatonConstructor - public System(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized); - } - - /** - * [CONSTRUCTOR] SystemAutomaton::(LSLSystem) -> void - * Source: java/lang/System.main.lsl:226 - */ - private System() { - this((Void) null); - /* body */ { - } - } - - /** - * [SUBROUTINE] SystemAutomaton::_initProperties() -> void - * Source: java/lang/System.main.lsl:97 - */ - private static void _initProperties() { - /* body */ { - final LibSLRuntime.Map pm = propsMap; - final int javaVersion = 8; - final String userName = "Admin"; - pm.set("file.encoding", "Cp1251"); - pm.set("sun.io.unicode.encoding", "UnicodeLittle"); - pm.set("sun.jnu.encoding", "Cp1251"); - pm.set("sun.stderr.encoding", "cp866"); - pm.set("sun.stdout.encoding", "cp866"); - final String[] versionStrings = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" }; - final String versionString = versionStrings[javaVersion]; - pm.set("java.specification.name", "Java Platform API Specification"); - pm.set("java.specification.vendor", "Oracle Corporation"); - pm.set("java.specification.version", versionString); - pm.set("java.vm.info", "mixed mode"); - pm.set("java.vm.name", "OpenJDK 64-Bit Server VM"); - pm.set("java.vm.specification.name", "Java Virtual Machine Specification"); - pm.set("java.vm.specification.vendor", "Oracle Corporation"); - pm.set("java.vm.specification.version", versionString); - pm.set("java.vm.vendor", "Eclipse Adoptium"); - pm.set("java.vm.version", versionString.concat(".0.362+9")); - pm.set("java.library.path", "C:\\Program Files\\Eclipse Adoptium\\jdk-8.0.362.9-hotspot\\bin;C:\\Windows\\Sun\\Java\\bin;C:\\Windows\\system32;."); - pm.set("java.home", "C:\\Program Files\\Eclipse Adoptium\\jdk-8.0.362.9-hotspot"); - pm.set("sun.boot.library.path", "C:\\Program Files\\Eclipse Adoptium\\jdk-8.0.362.9-hotspot\\bin"); - pm.set("java.io.tmpdir", "T:\\Temp\\"); - pm.set("java.class.path", "."); - if (LibSLGlobals.SYSTEM_IS_WINDOWS) { - pm.set("file.separator", "\\"); - pm.set("line.separator", "\r\n"); - pm.set("path.separator", ";"); - } else { - pm.set("file.separator", "/"); - pm.set("line.separator", "\n"); - pm.set("path.separator", ":"); - } - pm.set("user.country", "RU"); - pm.set("user.country.format", "US"); - pm.set("user.language", "ru"); - final String[] bytecodeVersions = { "?", "?", "?", "?", "?", "49.0", "50.0", "51.0", "52.0", "53.0", "54.0", "55.0", "?", "?", "?", "?" }; - pm.set("java.class.version", bytecodeVersions[javaVersion]); - pm.set("os.arch", "amd64"); - pm.set("os.name", "Windows 10"); - pm.set("os.version", "10.0"); - pm.set("sun.arch.data.model", "64"); - pm.set("sun.cpu.endian", "little"); - pm.set("sun.cpu.isalist", "amd64"); - pm.set("sun.desktop", "windows"); - pm.set("user.dir", "D:\\Company\\Prod\\Service"); - pm.set("user.home", "C:\\Users\\".concat(userName)); - pm.set("user.name", userName); - pm.set("user.script", ""); - pm.set("user.timezone", ""); - pm.set("user.variant", ""); - pm.set("sun.java.command", "org.example.MainClass"); - pm.set("awt.toolkit", "sun.awt.windows.WToolkit"); - pm.set("java.awt.graphicsenv", "sun.awt.Win32GraphicsEnvironment"); - pm.set("java.awt.printerjob", "sun.awt.windows.WPrinterJob"); - pm.set("sun.java.launcher", "SUN_STANDARD"); - pm.set("sun.management.compiler", "HotSpot 64-Bit Tiered Compilers"); - pm.set("sun.nio.MaxDirectMemorySize", "-1"); - pm.set("sun.os.patch.level", ""); - pm.set("java.vm.compressedOopsMode", "Zero based"); - pm.set("jdk.boot.class.path.append", ""); - pm.set("jdk.debug", "release"); - props = null; - } - } - - /** - * [SUBROUTINE] SystemAutomaton::initPhase1() -> void - * Source: java/lang/System.main.lsl:541 - */ - private static void initPhase1() { - /* body */ { - _initProperties(); - final InputStream newInput = (SymbolicInputStream) ((Object) new generated.libsl.utils.SymbolicInputStream((Void) null, - /* state = */ generated.libsl.utils.SymbolicInputStream.__$lsl_States.Initialized, - /* maxSize = */ 1000, - /* supportMarks = */ false, - /* dataSize = */ -1, - /* data = */ null, - /* closed = */ false, - /* pos = */ 0, - /* markPos = */ -1, - /* markLimit = */ 0 - )); - in = newInput; - out = (stub.java.lang.System_PrintStream) ((Object) new System_PrintStream((Void) null, - /* state = */ System_PrintStream.__$lsl_States.Initialized, - /* closed = */ false, - /* error = */ false - )); - err = (stub.java.lang.System_PrintStream) ((Object) new System_PrintStream((Void) null, - /* state = */ System_PrintStream.__$lsl_States.Initialized, - /* closed = */ false, - /* error = */ false - )); - VM.initLevel(1); - } - } - - /** - * [SUBROUTINE] SystemAutomaton::initPhase2() -> int - * Source: java/lang/System.main.lsl:581 - */ - private static int initPhase2() { - int result = 0; - /* body */ { - VM.initLevel(2); - result = 0; - } - return result; - } - - /** - * [SUBROUTINE] SystemAutomaton::initPhase3() -> void - * Source: java/lang/System.main.lsl:593 - */ - private static void initPhase3() { - /* body */ { - security = null; - VM.initLevel(3); - VM.initLevel(4); - } - } - - /** - * [FUNCTION] SystemAutomaton::clearProperty(String) -> String - * Source: java/lang/System.main.lsl:240 - */ - public static String clearProperty(String key) { - String result = null; - /* body */ { - if (key == null) { - throw new NullPointerException("key can\'t be null"); - } - if (key.length() == 0) { - throw new NullPointerException("key can\'t be empty"); - } - final SecurityManager sm = security; - if (sm != null) { - sm.checkPermission(new java.util.PropertyPermission(key, "write")); - } - final LibSLRuntime.Map pm = propsMap; - if (pm.hasKey(key)) { - result = pm.get(key); - pm.remove(key); - } - } - return result; - } - - /** - * [FUNCTION] SystemAutomaton::console() -> Console - * Source: java/lang/System.main.lsl:262 - */ - public static Console console() { - Console result = null; - /* body */ { - result = console; - } - return result; - } - - /** - * [FUNCTION] SystemAutomaton::exit(int) -> void - * Source: java/lang/System.main.lsl:275 - */ - public static void exit(int status) { - /* body */ { - LibSLRuntime.error("Unexpected shutdown"); - } - } - - /** - * [FUNCTION] SystemAutomaton::gc() -> void - * Source: java/lang/System.main.lsl:282 - */ - public static void gc() { - /* body */ { - } - } - - /** - * [FUNCTION] SystemAutomaton::getProperties() -> Properties - * Source: java/lang/System.main.lsl:300 - */ - public static Properties getProperties() { - Properties result = null; - /* body */ { - final SecurityManager sm = security; - if (sm != null) { - sm.checkPropertiesAccess(); - } - result = props; - } - return result; - } - - /** - * [FUNCTION] SystemAutomaton::getProperty(String) -> String - * Source: java/lang/System.main.lsl:310 - */ - public static String getProperty(String key) { - String result = null; - /* body */ { - if (key == null) { - throw new NullPointerException("key can\'t be null"); - } - if (key.length() == 0) { - throw new NullPointerException("key can\'t be empty"); - } - final SecurityManager sm = security; - if (sm != null) { - sm.checkPropertyAccess(key); - } - final LibSLRuntime.Map pm = propsMap; - if (pm.hasKey(key)) { - result = pm.get(key); - } else { - result = null; - } - } - return result; - } - - /** - * [FUNCTION] SystemAutomaton::getProperty(String, String) -> String - * Source: java/lang/System.main.lsl:326 - */ - public static String getProperty(String key, String def) { - String result = null; - /* body */ { - if (key == null) { - throw new NullPointerException("key can\'t be null"); - } - if (key.length() == 0) { - throw new NullPointerException("key can\'t be empty"); - } - final SecurityManager sm = security; - if (sm != null) { - sm.checkPropertyAccess(key); - } - final LibSLRuntime.Map pm = propsMap; - if (pm.hasKey(key)) { - result = pm.get(key); - } else { - result = def; - } - } - return result; - } - - /** - * [FUNCTION] SystemAutomaton::getSecurityManager() -> SecurityManager - * Source: java/lang/System.main.lsl:342 - */ - public static SecurityManager getSecurityManager() { - SecurityManager result = null; - /* body */ { - result = security; - } - return result; - } - - /** - * [FUNCTION] SystemAutomaton::getenv(String) -> String - * Source: java/lang/System.main.lsl:362 - */ - public static String getenv(String name) { - String result = null; - /* body */ { - final SecurityManager sm = security; - if (sm != null) { - sm.checkPermission(new RuntimePermission("getenv.".concat(name))); - } - result = Engine.makeSymbolic(String.class); - Engine.assume(result != null); - final int len = result.length(); - Engine.assume(len >= 0); - Engine.assume(len < 250); - } - return result; - } - - /** - * [FUNCTION] SystemAutomaton::identityHashCode(Object) -> int - * Source: java/lang/System.main.lsl:379 - */ - public static int identityHashCode(Object x) { - int result = 0; - /* body */ { - if (x == null) { - result = 0; - } else { - if (identityHashCodeMap.hasKey(x)) { - final Integer value = identityHashCodeMap.get(x); - Engine.assume(value != null); - result = value.intValue(); - } else { - result = identityHashCodeMap.size(); - final Integer hash = Integer.valueOf(result); - identityHashCodeMap.set(x, hash); - } - } - } - return result; - } - - /** - * [FUNCTION] SystemAutomaton::lineSeparator() -> String - * Source: java/lang/System.main.lsl:409 - */ - public static String lineSeparator() { - String result = null; - /* body */ { - result = propsMap.get("line.separator"); - } - return result; - } - - /** - * [FUNCTION] SystemAutomaton::load(String) -> void - * Source: java/lang/System.main.lsl:415 - */ - public static void load(String filename) { - /* body */ { - if (filename == null) { - throw new NullPointerException(); - } - if (Engine.makeSymbolicBoolean()) { - throw new SecurityException(""); - } - if (Engine.makeSymbolicBoolean()) { - throw new UnsatisfiedLinkError(""); - } - } - } - - /** - * [FUNCTION] SystemAutomaton::loadLibrary(String) -> void - * Source: java/lang/System.main.lsl:426 - */ - public static void loadLibrary(String libname) { - /* body */ { - if (libname == null) { - throw new NullPointerException(); - } - if (Engine.makeSymbolicBoolean()) { - throw new SecurityException(""); - } - if (Engine.makeSymbolicBoolean()) { - throw new UnsatisfiedLinkError(""); - } - } - } - - /** - * [FUNCTION] SystemAutomaton::mapLibraryName(String) -> String - * Source: java/lang/System.main.lsl:437 - */ - public static String mapLibraryName(String libname) { - String result = null; - /* body */ { - if (libname == null) { - throw new NullPointerException(); - } - final int len = libname.length(); - if (len > 240) { - throw new IllegalArgumentException("name too long"); - } - if (LibSLGlobals.SYSTEM_IS_WINDOWS) { - result = libname.concat(".dll"); - } else { - if (LibSLGlobals.SYSTEM_IS_MAC) { - result = "lib".concat(libname).concat(".dylib"); - } else { - result = "lib".concat(libname).concat(".so"); - } - } - } - return result; - } - - /** - * [FUNCTION] SystemAutomaton::runFinalization() -> void - * Source: java/lang/System.main.lsl:463 - */ - public static void runFinalization() { - /* body */ { - } - } - - /** - * [FUNCTION] SystemAutomaton::setErr(PrintStream) -> void - * Source: java/lang/System.main.lsl:469 - */ - public static void setErr(PrintStream stream) { - /* body */ { - final SecurityManager sm = security; - if (sm != null) { - sm.checkPermission(new RuntimePermission("setIO")); - } - err = stream; - } - } - - /** - * [FUNCTION] SystemAutomaton::setIn(InputStream) -> void - * Source: java/lang/System.main.lsl:476 - */ - public static void setIn(InputStream stream) { - /* body */ { - final SecurityManager sm = security; - if (sm != null) { - sm.checkPermission(new RuntimePermission("setIO")); - } - in = stream; - } - } - - /** - * [FUNCTION] SystemAutomaton::setOut(PrintStream) -> void - * Source: java/lang/System.main.lsl:483 - */ - public static void setOut(PrintStream stream) { - /* body */ { - final SecurityManager sm = security; - if (sm != null) { - sm.checkPermission(new RuntimePermission("setIO")); - } - out = stream; - } - } - - /** - * [FUNCTION] SystemAutomaton::setProperties(Properties) -> void - * Source: java/lang/System.main.lsl:490 - */ - public static void setProperties(Properties p) { - /* body */ { - final SecurityManager sm = security; - if (sm != null) { - sm.checkPropertiesAccess(); - } - props = p; - } - } - - /** - * [FUNCTION] SystemAutomaton::setProperty(String, String) -> String - * Source: java/lang/System.main.lsl:501 - */ - public static String setProperty(String key, String value) { - String result = null; - /* body */ { - if (key == null) { - throw new NullPointerException("key can\'t be null"); - } - if (key.length() == 0) { - throw new NullPointerException("key can\'t be empty"); - } - final SecurityManager sm = security; - if (sm != null) { - sm.checkPermission(new java.util.PropertyPermission(key, "write")); - } - final LibSLRuntime.Map pm = propsMap; - if (pm.hasKey(key)) { - result = pm.get(key); - } else { - result = null; - } - pm.set(key, value); - } - return result; - } - - /** - * [FUNCTION] SystemAutomaton::setSecurityManager(SecurityManager) -> void - * Source: java/lang/System.main.lsl:523 - */ - public static void setSecurityManager(SecurityManager s) { - /* body */ { - final SecurityManager sm = security; - if (sm != null) { - sm.checkPermission(new RuntimePermission("setSecurityManager")); - } - security = s; - } - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(System.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/lang/SystemImpl.java b/approximations/src/main/java/generated/java/lang/SystemImpl.java new file mode 100644 index 00000000..b91d594a --- /dev/null +++ b/approximations/src/main/java/generated/java/lang/SystemImpl.java @@ -0,0 +1,329 @@ +package generated.java.lang; + +import generated.libsl.utils.SymbolicInputStreamImpl; +import generated.runtime.LibSLGlobals; +import java.io.Console; +import java.io.InputStream; +import java.io.PrintStream; +import java.lang.IllegalArgumentException; +import java.lang.Integer; +import java.lang.NullPointerException; +import java.lang.Object; +import java.lang.SecurityException; +import java.lang.String; +import java.lang.UnsatisfiedLinkError; +import java.util.Properties; +import jdk.internal.misc.VM; +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +@SuppressWarnings({"unused", "removal"}) +@Approximate(java.lang.System.class) +public final class SystemImpl { + private static final LibSLRuntime.Map propsMap = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); + + private static volatile SecurityManager security = null; + + private static Properties props = null; + + @SuppressWarnings("FieldMayBeFinal") + private static Console console = null; + + public static InputStream in = null; + + public static PrintStream out = null; + + public static PrintStream err = null; + + private static final long NANOTIME_BEGINNING_OF_TIME = 1000L; + + private static final long NANOTIME_WARP_MAX = 1000L; + + private static final LibSLRuntime.Map identityHashCodeMap = new LibSLRuntime.Map<>(new LibSLRuntime.IdentityMapContainer<>()); + + static { + initPhase1(); + initPhase2(); + initPhase3(); + } + + private SystemImpl() { } + + private static void _initProperties() { + LibSLRuntime.Map pm = propsMap; + int javaVersion = 8; + String userName = "Admin"; + pm.set("file.encoding", "Cp1251"); + pm.set("sun.io.unicode.encoding", "UnicodeLittle"); + pm.set("sun.jnu.encoding", "Cp1251"); + pm.set("sun.stderr.encoding", "cp866"); + pm.set("sun.stdout.encoding", "cp866"); + String[] versionStrings = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" }; + String versionString = versionStrings[javaVersion]; + pm.set("java.specification.name", "Java Platform API Specification"); + pm.set("java.specification.vendor", "Oracle Corporation"); + pm.set("java.specification.version", versionString); + pm.set("java.vm.info", "mixed mode"); + pm.set("java.vm.name", "OpenJDK 64-Bit Server VM"); + pm.set("java.vm.specification.name", "Java Virtual Machine Specification"); + pm.set("java.vm.specification.vendor", "Oracle Corporation"); + pm.set("java.vm.specification.version", versionString); + pm.set("java.vm.vendor", "Eclipse Adoptium"); + pm.set("java.vm.version", versionString.concat(".0.362+9")); + pm.set("java.library.path", "C:\\Program Files\\Eclipse Adoptium\\jdk-8.0.362.9-hotspot\\bin;C:\\Windows\\Sun\\Java\\bin;C:\\Windows\\system32;."); + pm.set("java.home", "C:\\Program Files\\Eclipse Adoptium\\jdk-8.0.362.9-hotspot"); + pm.set("sun.boot.library.path", "C:\\Program Files\\Eclipse Adoptium\\jdk-8.0.362.9-hotspot\\bin"); + pm.set("java.io.tmpdir", "T:\\Temp\\"); + pm.set("java.class.path", "."); + if (LibSLGlobals.SYSTEM_IS_WINDOWS) { + pm.set("file.separator", "\\"); + pm.set("line.separator", "\r\n"); + pm.set("path.separator", ";"); + } else { + pm.set("file.separator", "/"); + pm.set("line.separator", "\n"); + pm.set("path.separator", ":"); + } + pm.set("user.country", "RU"); + pm.set("user.country.format", "US"); + pm.set("user.language", "ru"); + String[] bytecodeVersions = { "?", "?", "?", "?", "?", "49.0", "50.0", "51.0", "52.0", "53.0", "54.0", "55.0", "?", "?", "?", "?" }; + pm.set("java.class.version", bytecodeVersions[javaVersion]); + pm.set("os.arch", "amd64"); + pm.set("os.name", "Windows 10"); + pm.set("os.version", "10.0"); + pm.set("sun.arch.data.model", "64"); + pm.set("sun.cpu.endian", "little"); + pm.set("sun.cpu.isalist", "amd64"); + pm.set("sun.desktop", "windows"); + pm.set("user.dir", "D:\\Company\\Prod\\Service"); + pm.set("user.home", "C:\\Users\\".concat(userName)); + pm.set("user.name", userName); + pm.set("user.script", ""); + pm.set("user.timezone", ""); + pm.set("user.variant", ""); + pm.set("sun.java.command", "org.example.MainClass"); + pm.set("awt.toolkit", "sun.awt.windows.WToolkit"); + pm.set("java.awt.graphicsenv", "sun.awt.Win32GraphicsEnvironment"); + pm.set("java.awt.printerjob", "sun.awt.windows.WPrinterJob"); + pm.set("sun.java.launcher", "SUN_STANDARD"); + pm.set("sun.management.compiler", "HotSpot 64-Bit Tiered Compilers"); + pm.set("sun.nio.MaxDirectMemorySize", "-1"); + pm.set("sun.os.patch.level", ""); + pm.set("java.vm.compressedOopsMode", "Zero based"); + pm.set("jdk.boot.class.path.append", ""); + pm.set("jdk.debug", "release"); + props = null; + } + + @SuppressWarnings("DataFlowIssue") + private static void initPhase1() { + _initProperties(); + in = new SymbolicInputStreamImpl(1000, false, -1, null, false, 0, -1, 0); + out = (PrintStream) (Object) new System_PrintStreamImpl(false, false); + err = (PrintStream) (Object) new System_PrintStreamImpl(false, false); + VM.initLevel(1); + } + + @SuppressWarnings("UnusedReturnValue") + private static int initPhase2() { + VM.initLevel(2); + return 0; + } + + private static void initPhase3() { + security = null; + VM.initLevel(3); + VM.initLevel(4); + } + + private static void _checkKey(String key) { + if (key == null) + throw new NullPointerException("key can't be null"); + if (key.isEmpty()) + throw new NullPointerException("key can't be empty"); + } + + public static String clearProperty(String key) { + _checkKey(key); + SecurityManager sm = security; + if (sm != null) + sm.checkPermission(new java.util.PropertyPermission(key, "write")); + LibSLRuntime.Map pm = propsMap; + if (!pm.hasKey(key)) + return null; + + String result = pm.get(key); + pm.remove(key); + return result; + } + + public static Console console() { + return console; + } + + public static void exit(int status) { + LibSLRuntime.error("Unexpected shutdown"); + } + + public static void gc() { } + + public static Properties getProperties() { + SecurityManager sm = security; + if (sm != null) + sm.checkPropertiesAccess(); + return props; + } + + public static String getProperty(String key) { + _checkKey(key); + SecurityManager sm = security; + if (sm != null) + sm.checkPropertyAccess(key); + LibSLRuntime.Map pm = propsMap; + if (!pm.hasKey(key)) + return null; + + return pm.get(key); + } + + public static String getProperty(String key, String def) { + _checkKey(key); + SecurityManager sm = security; + if (sm != null) { + sm.checkPropertyAccess(key); + } + LibSLRuntime.Map pm = propsMap; + if (pm.hasKey(key)) + return pm.get(key); + + return def; + } + + public static SecurityManager getSecurityManager() { + return security; + } + + @SuppressWarnings({"ConstantValue", "DataFlowIssue"}) + public static String getenv(String name) { + SecurityManager sm = security; + if (sm != null) + sm.checkPermission(new RuntimePermission("getenv.".concat(name))); + String result = Engine.makeSymbolic(String.class); + Engine.assume(result != null); + int len = result.length(); + Engine.assume(len >= 0); + Engine.assume(len < 250); + return result; + } + + @SuppressWarnings("DataFlowIssue") + public static int identityHashCode(Object x) { + if (x == null) + return 0; + + if (identityHashCodeMap.hasKey(x)) { + Integer value = identityHashCodeMap.get(x); + Engine.assume(value != null); + return value; + } + + int result = identityHashCodeMap.size(); + identityHashCodeMap.set(x, result); + return result; + } + + public static String lineSeparator() { + return propsMap.get("line.separator"); + } + + @SuppressWarnings({"DuplicateCondition", "ConstantValue"}) + public static void load(String filename) { + if (filename == null) + throw new NullPointerException(); + if (Engine.makeSymbolicBoolean()) + throw new SecurityException(""); + if (Engine.makeSymbolicBoolean()) + throw new UnsatisfiedLinkError(""); + } + + @SuppressWarnings({"DuplicateCondition", "ConstantValue"}) + public static void loadLibrary(String libName) { + if (libName == null) + throw new NullPointerException(); + if (Engine.makeSymbolicBoolean()) { + throw new SecurityException(""); + } + if (Engine.makeSymbolicBoolean()) { + throw new UnsatisfiedLinkError(""); + } + } + + public static String mapLibraryName(String libName) { + if (libName == null) + throw new NullPointerException(); + + int len = libName.length(); + if (len > 240) + throw new IllegalArgumentException("name too long"); + + if (LibSLGlobals.SYSTEM_IS_WINDOWS) + return libName.concat(".dll"); + + if (LibSLGlobals.SYSTEM_IS_MAC) + return "lib".concat(libName).concat(".dylib"); + + return "lib".concat(libName).concat(".so"); + } + + public static void runFinalization() { } + + public static void setErr(PrintStream stream) { + if (security != null) + security.checkPermission(new RuntimePermission("setIO")); + err = stream; + } + + public static void setIn(InputStream stream) { + if (security != null) + security.checkPermission(new RuntimePermission("setIO")); + in = stream; + } + + public static void setOut(PrintStream stream) { + if (security != null) + security.checkPermission(new RuntimePermission("setIO")); + out = stream; + } + + public static void setProperties(Properties p) { + if (security != null) + security.checkPropertiesAccess(); + props = p; + } + + public static String setProperty(String key, String value) { + if (key == null) + throw new NullPointerException("key can't be null"); + if (key.isEmpty()) + throw new NullPointerException("key can't be empty"); + if (security != null) + security.checkPermission(new java.util.PropertyPermission(key, "write")); + LibSLRuntime.Map pm = propsMap; + String result; + if (pm.hasKey(key)) { + result = pm.get(key); + } else { + result = null; + } + pm.set(key, value); + return result; + } + + public static void setSecurityManager(SecurityManager s) { + if (security != null) + security.checkPermission(new RuntimePermission("setSecurityManager")); + security = s; + } +} diff --git a/approximations/src/main/java/generated/java/lang/System_PrintStream.java b/approximations/src/main/java/generated/java/lang/System_PrintStream.java deleted file mode 100644 index 21623644..00000000 --- a/approximations/src/main/java/generated/java/lang/System_PrintStream.java +++ /dev/null @@ -1,496 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/lang/System.lsl:83 -// - java/lang/System.StdOut.lsl:22 -// -package generated.java.lang; - -import java.io.PrintStream; -import java.lang.CharSequence; -import java.lang.IndexOutOfBoundsException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.String; -import java.lang.StringIndexOutOfBoundsException; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Locale; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * System_PrintStreamAutomaton for System_PrintStream ~> java.lang.System_PrintStream - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.lang.System_PrintStream.class) -public final class System_PrintStream implements LibSLRuntime.Automaton { - static { - Engine.assume(true); - } - - public boolean closed; - - public boolean error; - - @LibSLRuntime.AutomatonConstructor - public System_PrintStream(Void __$lsl_token, final byte p0, final boolean p1, - final boolean p2) { - this.closed = p1; - this.error = p2; - } - - @LibSLRuntime.AutomatonConstructor - public System_PrintStream(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, false, false); - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::append(System_PrintStream, CharSequence) -> PrintStream - * Source: java/lang/System.StdOut.lsl:94 - */ - public PrintStream append(CharSequence csq) { - PrintStream result = null; - /* body */ { - if (this.closed) { - this.error = true; - } - result = ((PrintStream) ((Object) this)); - } - return result; - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::append(System_PrintStream, CharSequence, int, int) -> PrintStream - * Source: java/lang/System.StdOut.lsl:102 - */ - public PrintStream append(CharSequence csq, int start, int end) { - PrintStream result = null; - /* body */ { - if (csq == null) { - csq = "null"; - } - final int size = csq.length(); - if ((start < 0) || (end >= size)) { - throw new StringIndexOutOfBoundsException(); - } - if (this.closed) { - this.error = true; - } - result = ((PrintStream) ((Object) this)); - } - return result; - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::append(System_PrintStream, char) -> PrintStream - * Source: java/lang/System.StdOut.lsl:117 - */ - public PrintStream append(char c) { - PrintStream result = null; - /* body */ { - if (this.closed) { - this.error = true; - } - result = ((PrintStream) ((Object) this)); - } - return result; - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::checkError(System_PrintStream) -> boolean - * Source: java/lang/System.StdOut.lsl:125 - */ - public boolean checkError() { - boolean result = false; - /* body */ { - result = this.error; - } - return result; - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::close(System_PrintStream) -> void - * Source: java/lang/System.StdOut.lsl:131 - */ - public void close() { - /* body */ { - this.closed = true; - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::flush(System_PrintStream) -> void - * Source: java/lang/System.StdOut.lsl:138 - */ - public void flush() { - /* body */ { - if (this.closed) { - this.error = true; - } - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::format(System_PrintStream, Locale, String, array) -> PrintStream - * Source: java/lang/System.StdOut.lsl:145 - */ - public PrintStream format(Locale l, String format, Object[] args) { - PrintStream result = null; - /* body */ { - if (format == null) { - throw new NullPointerException(); - } - if (this.closed) { - this.error = true; - } - result = ((PrintStream) ((Object) this)); - } - return result; - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::format(System_PrintStream, String, array) -> PrintStream - * Source: java/lang/System.StdOut.lsl:156 - */ - public PrintStream format(String format, Object[] args) { - PrintStream result = null; - /* body */ { - if (format == null) { - throw new NullPointerException(); - } - if (this.closed) { - this.error = true; - } - result = ((PrintStream) ((Object) this)); - } - return result; - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::print(System_PrintStream, Object) -> void - * Source: java/lang/System.StdOut.lsl:167 - */ - public void print(Object obj) { - /* body */ { - if (this.closed) { - this.error = true; - } - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::print(System_PrintStream, String) -> void - * Source: java/lang/System.StdOut.lsl:173 - */ - public void print(String s) { - /* body */ { - if (this.closed) { - this.error = true; - } - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::print(System_PrintStream, boolean) -> void - * Source: java/lang/System.StdOut.lsl:179 - */ - public void print(boolean b) { - /* body */ { - if (this.closed) { - this.error = true; - } - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::print(System_PrintStream, char) -> void - * Source: java/lang/System.StdOut.lsl:185 - */ - public void print(char c) { - /* body */ { - if (this.closed) { - this.error = true; - } - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::print(System_PrintStream, array) -> void - * Source: java/lang/System.StdOut.lsl:191 - */ - public void print(char[] s) { - /* body */ { - if (s == null) { - throw new NullPointerException(); - } - if (this.closed) { - this.error = true; - } - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::print(System_PrintStream, double) -> void - * Source: java/lang/System.StdOut.lsl:200 - */ - public void print(double d) { - /* body */ { - if (this.closed) { - this.error = true; - } - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::print(System_PrintStream, float) -> void - * Source: java/lang/System.StdOut.lsl:206 - */ - public void print(float f) { - /* body */ { - if (this.closed) { - this.error = true; - } - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::print(System_PrintStream, int) -> void - * Source: java/lang/System.StdOut.lsl:212 - */ - public void print(int i) { - /* body */ { - if (this.closed) { - this.error = true; - } - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::print(System_PrintStream, long) -> void - * Source: java/lang/System.StdOut.lsl:218 - */ - public void print(long l) { - /* body */ { - if (this.closed) { - this.error = true; - } - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::printf(System_PrintStream, Locale, String, array) -> PrintStream - * Source: java/lang/System.StdOut.lsl:224 - */ - public PrintStream printf(Locale l, String format, Object[] args) { - PrintStream result = null; - /* body */ { - if ((l == null) || (format == null) || (args == null)) { - throw new NullPointerException(); - } - if (this.closed) { - this.error = true; - } - result = ((PrintStream) ((Object) this)); - } - return result; - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::printf(System_PrintStream, String, array) -> PrintStream - * Source: java/lang/System.StdOut.lsl:235 - */ - public PrintStream printf(String format, Object[] args) { - PrintStream result = null; - /* body */ { - if ((format == null) || (args == null)) { - throw new NullPointerException(); - } - if (this.closed) { - this.error = true; - } - result = ((PrintStream) ((Object) this)); - } - return result; - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::println(System_PrintStream) -> void - * Source: java/lang/System.StdOut.lsl:246 - */ - public void println() { - /* body */ { - if (this.closed) { - this.error = true; - } - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::println(System_PrintStream, Object) -> void - * Source: java/lang/System.StdOut.lsl:252 - */ - public void println(Object x) { - /* body */ { - if (this.closed) { - this.error = true; - } - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::println(System_PrintStream, String) -> void - * Source: java/lang/System.StdOut.lsl:258 - */ - public void println(String x) { - /* body */ { - if (this.closed) { - this.error = true; - } - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::println(System_PrintStream, boolean) -> void - * Source: java/lang/System.StdOut.lsl:264 - */ - public void println(boolean x) { - /* body */ { - if (this.closed) { - this.error = true; - } - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::println(System_PrintStream, char) -> void - * Source: java/lang/System.StdOut.lsl:270 - */ - public void println(char x) { - /* body */ { - if (this.closed) { - this.error = true; - } - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::println(System_PrintStream, array) -> void - * Source: java/lang/System.StdOut.lsl:276 - */ - public void println(char[] x) { - /* body */ { - if (x == null) { - throw new NullPointerException(); - } - if (this.closed) { - this.error = true; - } - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::println(System_PrintStream, double) -> void - * Source: java/lang/System.StdOut.lsl:285 - */ - public void println(double x) { - /* body */ { - if (this.closed) { - this.error = true; - } - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::println(System_PrintStream, float) -> void - * Source: java/lang/System.StdOut.lsl:291 - */ - public void println(float x) { - /* body */ { - if (this.closed) { - this.error = true; - } - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::println(System_PrintStream, int) -> void - * Source: java/lang/System.StdOut.lsl:297 - */ - public void println(int x) { - /* body */ { - if (this.closed) { - this.error = true; - } - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::println(System_PrintStream, long) -> void - * Source: java/lang/System.StdOut.lsl:303 - */ - public void println(long x) { - /* body */ { - if (this.closed) { - this.error = true; - } - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::write(System_PrintStream, array) -> void - * Source: java/lang/System.StdOut.lsl:309 - */ - public void write(byte[] b) throws java.io.IOException { - /* body */ { - if (b == null) { - throw new NullPointerException(); - } - if (this.closed) { - this.error = true; - } - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::write(System_PrintStream, array, int, int) -> void - * Source: java/lang/System.StdOut.lsl:320 - */ - public void write(byte[] buf, int off, int len) { - /* body */ { - if (buf == null) { - throw new NullPointerException(); - } - final int size = buf.length; - if ((off < 0) || ((off + len) > size)) { - throw new IndexOutOfBoundsException(); - } - if (this.closed) { - this.error = true; - } - } - } - - /** - * [FUNCTION] System_PrintStreamAutomaton::write(System_PrintStream, int) -> void - * Source: java/lang/System.StdOut.lsl:333 - */ - public void write(int b) { - /* body */ { - if (this.closed) { - this.error = true; - } - } - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(System_PrintStream.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/lang/System_PrintStreamImpl.java b/approximations/src/main/java/generated/java/lang/System_PrintStreamImpl.java new file mode 100644 index 00000000..fe4ce756 --- /dev/null +++ b/approximations/src/main/java/generated/java/lang/System_PrintStreamImpl.java @@ -0,0 +1,204 @@ +package generated.java.lang; + +import java.io.PrintStream; +import java.lang.CharSequence; +import java.lang.IndexOutOfBoundsException; +import java.lang.NullPointerException; +import java.lang.Object; +import java.lang.String; +import java.lang.StringIndexOutOfBoundsException; +import java.util.Locale; + +import generated.libsl.utils.VoidOutputStreamImpl; +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import stub.java.lang.System_PrintStream; + +@Approximate(System_PrintStream.class) +public final class System_PrintStreamImpl { + + public boolean closed; + + public boolean error; + + public System_PrintStreamImpl(boolean closed, boolean error) { + this.closed = closed; + this.error = error; + } + + private void _checkClosed() { + if (this.closed) + this.error = true; + } + + public System_PrintStreamImpl append(CharSequence csq) { + _checkClosed(); + return this; + } + + public System_PrintStreamImpl append(CharSequence csq, int start, int end) { + if (csq == null) + csq = "null"; + int size = csq.length(); + if (start < 0 || end >= size) + throw new StringIndexOutOfBoundsException(); + _checkClosed(); + + return this; + } + + public System_PrintStreamImpl append(char c) { + _checkClosed(); + return this; + } + + public boolean checkError() { + return this.error; + } + + public void close() { + this.closed = true; + } + + public void flush() { + _checkClosed(); + } + + @SuppressWarnings("ConstantValue") + public System_PrintStreamImpl format(Locale l, @NotNull String format, Object... args) { + if (format == null) + throw new NullPointerException(); + _checkClosed(); + + return this; + } + + @SuppressWarnings("ConstantValue") + public System_PrintStreamImpl format(@NotNull String format, Object... args) { + if (format == null) + throw new NullPointerException(); + _checkClosed(); + + return this; + } + + public void print(Object obj) { + _checkClosed(); + } + + public void print(String s) { + _checkClosed(); + } + + public void print(boolean b) { + _checkClosed(); + } + + public void print(char c) { + _checkClosed(); + } + + @SuppressWarnings("ConstantValue") + public void print(@NotNull char[] s) { + if (s == null) + throw new NullPointerException(); + _checkClosed(); + } + + public void print(double d) { + _checkClosed(); + } + + public void print(float f) { + _checkClosed(); + } + + public void print(int i) { + _checkClosed(); + } + + public void print(long l) { + _checkClosed(); + } + + @SuppressWarnings("ConstantValue") + public System_PrintStreamImpl printf(Locale l, @NotNull String format, Object... args) { + if (l == null || format == null || args == null) + throw new NullPointerException(); + _checkClosed(); + + return this; + } + + @SuppressWarnings("ConstantValue") + public System_PrintStreamImpl printf(@NotNull String format, Object... args) { + if (format == null || args == null) + throw new NullPointerException(); + _checkClosed(); + return this; + } + + public void println() { + _checkClosed(); + } + + public void println(Object x) { + _checkClosed(); + } + + public void println(String x) { + _checkClosed(); + } + + public void println(boolean x) { + _checkClosed(); + } + + public void println(char x) { + _checkClosed(); + } + + @SuppressWarnings("ConstantValue") + public void println(@NotNull char[] x) { + if (x == null) + throw new NullPointerException(); + _checkClosed(); + } + + public void println(double x) { + _checkClosed(); + } + + public void println(float x) { + _checkClosed(); + } + + public void println(int x) { + _checkClosed(); + } + + public void println(long x) { + _checkClosed(); + } + + @SuppressWarnings("RedundantThrows") + public void write(byte[] b) throws java.io.IOException { + if (b == null) + throw new NullPointerException(); + _checkClosed(); + } + + @SuppressWarnings("ConstantValue") + public void write(@NotNull byte[] buf, int off, int len) { + if (buf == null) + throw new NullPointerException(); + int size = buf.length; + if (off < 0 || off + len > size) + throw new IndexOutOfBoundsException(); + _checkClosed(); + } + + public void write(int b) { + _checkClosed(); + } +} diff --git a/approximations/src/main/java/generated/java/lang/ThreadLocalImpl.java b/approximations/src/main/java/generated/java/lang/ThreadLocalImpl.java new file mode 100644 index 00000000..f1c6973f --- /dev/null +++ b/approximations/src/main/java/generated/java/lang/ThreadLocalImpl.java @@ -0,0 +1,28 @@ +package generated.java.lang; + +import org.jacodb.approximation.annotation.Approximate; + +import java.util.function.Supplier; + +@Approximate(java.lang.ThreadLocal.class) +public class ThreadLocalImpl { + private T storage = null; + + public static ThreadLocal withInitial(Supplier supplier) { + ThreadLocal local = new ThreadLocal<>(); + local.set(supplier.get()); + return local; + } + + public T get() { + return storage; + } + + public void set(T value) { + storage = value; + } + + public void remove() { + storage = null; + } +} diff --git a/approximations/src/main/java/generated/java/lang/Throwable.java b/approximations/src/main/java/generated/java/lang/Throwable.java deleted file mode 100644 index e27eddbe..00000000 --- a/approximations/src/main/java/generated/java/lang/Throwable.java +++ /dev/null @@ -1,125 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/lang/Throwable.lsl:25 -// - java/lang/Throwable.main.lsl:20 -// -package generated.java.lang; - -import java.io.Serializable; -import java.lang.StackTraceElement; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * ThrowableAutomaton for LSLThrowable ~> java.lang.Throwable - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.lang.Throwable.class) -public class Throwable implements LibSLRuntime.Automaton, Serializable { - private static final long serialVersionUID = -3042686055658047285L; - - private static final String NULL_CAUSE_MESSAGE = "Cannot suppress a null exception."; - - private static final String SELF_SUPPRESSION_MESSAGE = "Self-suppression not permitted"; - - private static final String CAUSE_CAPTION = "Caused by: "; - - private static final String SUPPRESSED_CAPTION = "Suppressed: "; - - static { - Engine.assume(true); - } - - @LibSLRuntime.AutomatonConstructor - public Throwable(Void __$lsl_token, final byte p0) { - } - - @LibSLRuntime.AutomatonConstructor - public Throwable(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized); - } - - /** - * [FUNCTION] ThrowableAutomaton::addSuppressed(LSLThrowable, Throwable) -> void - * Source: java/lang/Throwable.main.lsl:100 - */ - public final synchronized void addSuppressed(java.lang.Throwable exception) { - /* body */ { - } - } - - /** - * [FUNCTION] ThrowableAutomaton::fillInStackTrace(LSLThrowable) -> Throwable - * Source: java/lang/Throwable.main.lsl:106 - */ - public synchronized java.lang.Throwable fillInStackTrace() { - java.lang.Throwable result = null; - /* body */ { - result = Engine.makeSymbolic(java.lang.Throwable.class); - } - return result; - } - - /** - * [FUNCTION] ThrowableAutomaton::getStackTrace(LSLThrowable) -> array - * Source: java/lang/Throwable.main.lsl:133 - */ - public StackTraceElement[] getStackTrace() { - StackTraceElement[] result = null; - /* body */ { - final int size = Engine.makeSymbolicInt(); - Engine.assume(size >= 0); - Engine.assume(size < 99); - result = Engine.makeSymbolicArray(StackTraceElement.class, size); - } - return result; - } - - /** - * [FUNCTION] ThrowableAutomaton::getSuppressed(LSLThrowable) -> array - * Source: java/lang/Throwable.main.lsl:143 - */ - public final synchronized java.lang.Throwable[] getSuppressed() { - java.lang.Throwable[] result = null; - /* body */ { - final int size = Engine.makeSymbolicInt(); - Engine.assume(size >= 0); - Engine.assume(size < 99); - result = Engine.makeSymbolicArray(java.lang.Throwable.class, size); - } - return result; - } - - /** - * [FUNCTION] ThrowableAutomaton::printStackTrace(LSLThrowable) -> void - * Source: java/lang/Throwable.main.lsl:160 - */ - public void printStackTrace() { - /* body */ { - } - } - - /** - * [FUNCTION] ThrowableAutomaton::setStackTrace(LSLThrowable, array) -> void - * Source: java/lang/Throwable.main.lsl:180 - */ - public void setStackTrace(StackTraceElement[] stackTrace) { - /* body */ { - } - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(Throwable.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/lang/ThrowableImpl.java b/approximations/src/main/java/generated/java/lang/ThrowableImpl.java new file mode 100644 index 00000000..58bea77f --- /dev/null +++ b/approximations/src/main/java/generated/java/lang/ThrowableImpl.java @@ -0,0 +1,53 @@ +package generated.java.lang; + +import java.io.Serial; +import java.io.Serializable; +import java.lang.StackTraceElement; +import java.lang.String; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; + +@SuppressWarnings("unused") +@Approximate(java.lang.Throwable.class) +public class ThrowableImpl implements Serializable { + + @Serial + private static final long serialVersionUID = -3042686055658047285L; + + private static final String NULL_CAUSE_MESSAGE = "Cannot suppress a null exception."; + + private static final String SELF_SUPPRESSION_MESSAGE = "Self-suppression not permitted"; + + private static final String CAUSE_CAPTION = "Caused by: "; + + private static final String SUPPRESSED_CAPTION = "Suppressed: "; + + static { + Engine.assume(true); + } + + public final synchronized void addSuppressed(java.lang.Throwable exception) { } + + public synchronized java.lang.Throwable fillInStackTrace() { + return Engine.makeSymbolic(java.lang.Throwable.class); + } + + public StackTraceElement[] getStackTrace() { + int size = Engine.makeSymbolicInt(); + Engine.assume(size >= 0); + Engine.assume(size < 99); + return Engine.makeSymbolicArray(StackTraceElement.class, size); + } + + public final synchronized java.lang.Throwable[] getSuppressed() { + int size = Engine.makeSymbolicInt(); + Engine.assume(size >= 0); + Engine.assume(size < 99); + return Engine.makeSymbolicArray(java.lang.Throwable.class, size); + } + + public void printStackTrace() { } + + public void setStackTrace(StackTraceElement[] stackTrace) { } +} diff --git a/approximations/src/main/java/generated/java/security/SecureRandom.java b/approximations/src/main/java/generated/java/security/SecureRandom.java deleted file mode 100644 index 0ff09e8e..00000000 --- a/approximations/src/main/java/generated/java/security/SecureRandom.java +++ /dev/null @@ -1,840 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/security/SecureRandom.lsl:24 -// - java/security/SecureRandom.main.lsl:25 -// -package generated.java.security; - -import generated.runtime.LibSLGlobals; -import java.lang.IllegalArgumentException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.Provider; -import java.security.SecureRandomSpi; -import java.security.Security; -import java.util.stream.DoubleStream; -import java.util.stream.IntStream; -import java.util.stream.LongStream; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; -import stub.java.util.stream.DoubleStreamLSL; -import stub.java.util.stream.IntStreamLSL; -import stub.java.util.stream.LongStreamLSL; - -/** - * SecureRandomAutomaton for SecureRandomLSL ~> java.security.SecureRandom - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.security.SecureRandom.class) -public class SecureRandom implements LibSLRuntime.Automaton { - private static final long serialVersionUID = 4940670005562187L; - - private static final LibSLRuntime.Map defaultProvidersMap = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - - static { - /* SecureRandomAutomaton::() */ { - final LibSLRuntime.Map dpMap = defaultProvidersMap; - final Object o = LibSLGlobals.SOMETHING; - dpMap.set("SUN", o); - dpMap.set("SunRsaSign", o); - dpMap.set("SunJSSE", o); - dpMap.set("SunJCE", o); - dpMap.set("Apple", o); - dpMap.set("JdkLDAP", o); - dpMap.set("SunJGSS", o); - dpMap.set("SunSASL", o); - dpMap.set("SunPCSC", o); - dpMap.set("XMLDSig", o); - dpMap.set("SunPKCS11", o); - dpMap.set("SunEC", o); - dpMap.set("SunMSCAPI", o); - dpMap.set("OracleUcrypto", o); - dpMap.set("JdkSASL", o); - } - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public Provider provider; - - public String algorithm; - - public boolean defaultProvider; - - @LibSLRuntime.AutomatonConstructor - public SecureRandom(Void __$lsl_token, final byte p0, final Provider p1, final String p2, - final boolean p3) { - this.__$lsl_state = p0; - this.provider = p1; - this.algorithm = p2; - this.defaultProvider = p3; - } - - @LibSLRuntime.AutomatonConstructor - public SecureRandom(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, null, null, false); - } - - /** - * [CONSTRUCTOR] SecureRandomAutomaton::(SecureRandom) -> void - * Source: java/security/SecureRandom.main.lsl:218 - */ - public SecureRandom() { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - _getDefaultPRNG(); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] SecureRandomAutomaton::(SecureRandom, SecureRandomSpi, Provider) -> void - * Source: java/security/SecureRandom.main.lsl:224 - */ - protected SecureRandom(SecureRandomSpi secureRandomSpi, Provider provider) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - LibSLRuntime.error("Protected constructor call"); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] SecureRandomAutomaton::(SecureRandom, SecureRandomSpi, Provider, String) -> void - * Source: java/security/SecureRandom.main.lsl:230 - */ - private SecureRandom(SecureRandomSpi secureRandomSpi, Provider provider, String algorithm) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - LibSLRuntime.error("Private constructor call"); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] SecureRandomAutomaton::(SecureRandom, array) -> void - * Source: java/security/SecureRandom.main.lsl:236 - */ - public SecureRandom(byte[] seed) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - _getDefaultPRNG(); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] SecureRandomAutomaton::_getDefaultPRNG() -> void - * Source: java/security/SecureRandom.main.lsl:115 - */ - private void _getDefaultPRNG() { - /* body */ { - this.provider = null; - this.algorithm = "SHA1PRNG"; - this.defaultProvider = _isDefaultProvider(this.provider); - } - } - - /** - * [SUBROUTINE] SecureRandomAutomaton::_isDefaultProvider(Provider) -> boolean - * Source: java/security/SecureRandom.main.lsl:133 - */ - private static boolean _isDefaultProvider(Provider curProvider) { - boolean result = false; - /* body */ { - if (curProvider == null) { - result = false; - } else { - final String providerName = curProvider.getName(); - result = defaultProvidersMap.hasKey(providerName); - } - } - return result; - } - - /** - * [SUBROUTINE] SecureRandomAutomaton::_generateRandomIntegerArrayWithBounds(int, int, int) -> array - * Source: java/security/SecureRandom.main.lsl:147 - */ - private int[] _generateRandomIntegerArrayWithBounds(int size, int randomNumberOrigin, - int randomNumberBound) { - int[] result = null; - /* body */ { - result = Engine.makeSymbolicIntArray(size); - } - return result; - } - - /** - * [SUBROUTINE] SecureRandomAutomaton::_generateRandomLongArrayWithBounds(int, long, long) -> array - * Source: java/security/SecureRandom.main.lsl:169 - */ - private long[] _generateRandomLongArrayWithBounds(int size, long randomNumberOrigin, - long randomNumberBound) { - long[] result = null; - /* body */ { - result = Engine.makeSymbolicLongArray(size); - } - return result; - } - - /** - * [SUBROUTINE] SecureRandomAutomaton::_generateRandomDoubleArrayWithBounds(int, double, double) -> array - * Source: java/security/SecureRandom.main.lsl:191 - */ - private double[] _generateRandomDoubleArrayWithBounds(int size, double randomNumberOrigin, - double randomNumberBound) { - double[] result = null; - /* body */ { - result = Engine.makeSymbolicDoubleArray(size); - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::getInstance(String) -> SecureRandom - * Source: java/security/SecureRandom.main.lsl:244 - */ - public static java.security.SecureRandom getInstance(String _algorithm) throws - java.security.NoSuchAlgorithmException { - java.security.SecureRandom result = null; - // WARNING: no state checks in static context - /* body */ { - final Provider resultProvider = Engine.makeSymbolic(Provider.class); - final String resultAlgorithm = Engine.makeSymbolic(String.class); - if (resultAlgorithm == null) { - throw new NoSuchAlgorithmException(); - } - final int resultAlgorithmLength = resultAlgorithm.length(); - Engine.assume(resultAlgorithmLength > 0); - result = (java.security.SecureRandom) ((Object) new SecureRandom((Void) null, - /* state = */ SecureRandom.__$lsl_States.Initialized, - /* provider = */ resultProvider, - /* algorithm = */ resultAlgorithm, - /* defaultProvider = */ _isDefaultProvider(resultProvider) - )); - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::getInstance(String, Provider) -> SecureRandom - * Source: java/security/SecureRandom.main.lsl:264 - */ - public static java.security.SecureRandom getInstance(String _algorithm, Provider provider) - throws java.security.NoSuchAlgorithmException { - java.security.SecureRandom result = null; - // WARNING: no state checks in static context - /* body */ { - if (provider == null) { - throw new IllegalArgumentException(); - } - final Provider resultProvider = Engine.makeSymbolic(Provider.class); - final String resultAlgorithm = Engine.makeSymbolic(String.class); - if (resultAlgorithm == null) { - throw new NoSuchAlgorithmException(); - } - final int resultAlgorithmLength = resultAlgorithm.length(); - Engine.assume(resultAlgorithmLength > 0); - result = (java.security.SecureRandom) ((Object) new SecureRandom((Void) null, - /* state = */ SecureRandom.__$lsl_States.Initialized, - /* provider = */ resultProvider, - /* algorithm = */ resultAlgorithm, - /* defaultProvider = */ _isDefaultProvider(resultProvider) - )); - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::getInstance(String, String) -> SecureRandom - * Source: java/security/SecureRandom.main.lsl:287 - */ - public static java.security.SecureRandom getInstance(String _algorithm, String providerName) - throws java.security.NoSuchAlgorithmException, java.security.NoSuchProviderException { - java.security.SecureRandom result = null; - // WARNING: no state checks in static context - /* body */ { - if ((providerName == null) || (providerName.length() == 0)) { - throw new IllegalArgumentException(); - } - final Provider resultProvider = Engine.makeSymbolic(Provider.class); - final String resultAlgorithm = Engine.makeSymbolic(String.class); - if (resultProvider == null) { - throw new NoSuchProviderException(); - } - if (resultAlgorithm == null) { - throw new NoSuchAlgorithmException(); - } - final int resultAlgorithmLength = resultAlgorithm.length(); - Engine.assume(resultAlgorithmLength > 0); - result = (java.security.SecureRandom) ((Object) new SecureRandom((Void) null, - /* state = */ SecureRandom.__$lsl_States.Initialized, - /* provider = */ resultProvider, - /* algorithm = */ resultAlgorithm, - /* defaultProvider = */ _isDefaultProvider(resultProvider) - )); - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::getInstanceStrong() -> SecureRandom - * Source: java/security/SecureRandom.main.lsl:313 - */ - public static java.security.SecureRandom getInstanceStrong() throws - java.security.NoSuchAlgorithmException { - java.security.SecureRandom result = null; - // WARNING: no state checks in static context - /* body */ { - final String property = Security.getProperty("securerandom.strongAlgorithms"); - if (property == null) { - throw new NoSuchAlgorithmException(); - } - final int propertyLength = property.length(); - if (propertyLength == 0) { - throw new NoSuchAlgorithmException(); - } - final Provider resultProvider = Engine.makeSymbolic(Provider.class); - final String resultAlgorithm = Engine.makeSymbolic(String.class); - if (resultAlgorithm == null) { - throw new NoSuchAlgorithmException(); - } - result = (java.security.SecureRandom) ((Object) new SecureRandom((Void) null, - /* state = */ SecureRandom.__$lsl_States.Initialized, - /* provider = */ resultProvider, - /* algorithm = */ resultAlgorithm, - /* defaultProvider = */ _isDefaultProvider(resultProvider) - )); - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::getSeed(int) -> array - * Source: java/security/SecureRandom.main.lsl:341 - */ - public static byte[] getSeed(int numBytes) { - byte[] result = null; - // WARNING: no state checks in static context - /* body */ { - if (numBytes < 0) { - throw new IllegalArgumentException(); - } - result = Engine.makeSymbolicByteArray(numBytes); - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::doubles(SecureRandom) -> DoubleStream - * Source: java/security/SecureRandom.main.lsl:353 - */ - public DoubleStream doubles() { - DoubleStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (DoubleStreamLSL) ((Object) new generated.java.util.stream.DoubleStreamLSL((Void) null, - /* state = */ generated.java.util.stream.DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ _generateRandomDoubleArrayWithBounds(LibSLGlobals.RANDOM_STREAM_SIZE_MAX, 0, 1), - /* length = */ LibSLGlobals.RANDOM_STREAM_SIZE_MAX, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::doubles(SecureRandom, double, double) -> DoubleStream - * Source: java/security/SecureRandom.main.lsl:364 - */ - public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound) { - DoubleStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (randomNumberOrigin >= randomNumberBound) { - throw new IllegalArgumentException(); - } - result = (DoubleStreamLSL) ((Object) new generated.java.util.stream.DoubleStreamLSL((Void) null, - /* state = */ generated.java.util.stream.DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ _generateRandomDoubleArrayWithBounds(LibSLGlobals.RANDOM_STREAM_SIZE_MAX, randomNumberOrigin, randomNumberBound), - /* length = */ LibSLGlobals.RANDOM_STREAM_SIZE_MAX, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::doubles(SecureRandom, long) -> DoubleStream - * Source: java/security/SecureRandom.main.lsl:379 - */ - public DoubleStream doubles(long streamSize) { - DoubleStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - int size = ((int) streamSize); - if (size < 0) { - throw new IllegalArgumentException(); - } - if (size > LibSLGlobals.RANDOM_STREAM_SIZE_MAX) { - size = LibSLGlobals.RANDOM_STREAM_SIZE_MAX; - } - result = (DoubleStreamLSL) ((Object) new generated.java.util.stream.DoubleStreamLSL((Void) null, - /* state = */ generated.java.util.stream.DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ Engine.makeSymbolicDoubleArray(size), - /* length = */ size, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::doubles(SecureRandom, long, double, double) -> DoubleStream - * Source: java/security/SecureRandom.main.lsl:398 - */ - public DoubleStream doubles(long streamSize, double randomNumberOrigin, - double randomNumberBound) { - DoubleStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - int size = ((int) streamSize); - if (size < 0) { - throw new IllegalArgumentException(); - } - if (randomNumberOrigin >= randomNumberBound) { - throw new IllegalArgumentException(); - } - if (size > LibSLGlobals.RANDOM_STREAM_SIZE_MAX) { - size = LibSLGlobals.RANDOM_STREAM_SIZE_MAX; - } - result = (DoubleStreamLSL) ((Object) new generated.java.util.stream.DoubleStreamLSL((Void) null, - /* state = */ generated.java.util.stream.DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ _generateRandomDoubleArrayWithBounds(size, randomNumberOrigin, randomNumberBound), - /* length = */ size, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::generateSeed(SecureRandom, int) -> array - * Source: java/security/SecureRandom.main.lsl:418 - */ - public byte[] generateSeed(int numBytes) { - byte[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (numBytes < 0) { - throw new IllegalArgumentException(); - } - result = Engine.makeSymbolicByteArray(numBytes); - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::getAlgorithm(SecureRandom) -> String - * Source: java/security/SecureRandom.main.lsl:427 - */ - public String getAlgorithm() { - String result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.algorithm; - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::getProvider(SecureRandom) -> Provider - * Source: java/security/SecureRandom.main.lsl:433 - */ - public final Provider getProvider() { - Provider result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.provider; - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::ints(SecureRandom) -> IntStream - * Source: java/security/SecureRandom.main.lsl:440 - */ - public IntStream ints() { - IntStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (IntStreamLSL) ((Object) new generated.java.util.stream.IntStreamLSL((Void) null, - /* state = */ generated.java.util.stream.IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ Engine.makeSymbolicIntArray(LibSLGlobals.RANDOM_STREAM_SIZE_MAX), - /* length = */ LibSLGlobals.RANDOM_STREAM_SIZE_MAX, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::ints(SecureRandom, int, int) -> IntStream - * Source: java/security/SecureRandom.main.lsl:451 - */ - public IntStream ints(int randomNumberOrigin, int randomNumberBound) { - IntStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (randomNumberOrigin >= randomNumberBound) { - throw new IllegalArgumentException(); - } - result = (IntStreamLSL) ((Object) new generated.java.util.stream.IntStreamLSL((Void) null, - /* state = */ generated.java.util.stream.IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ _generateRandomIntegerArrayWithBounds(LibSLGlobals.RANDOM_STREAM_SIZE_MAX, randomNumberOrigin, randomNumberBound), - /* length = */ LibSLGlobals.RANDOM_STREAM_SIZE_MAX, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::ints(SecureRandom, long) -> IntStream - * Source: java/security/SecureRandom.main.lsl:465 - */ - public IntStream ints(long streamSize) { - IntStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - int size = ((int) streamSize); - if (size < 0) { - throw new IllegalArgumentException(); - } - if (size > LibSLGlobals.RANDOM_STREAM_SIZE_MAX) { - size = LibSLGlobals.RANDOM_STREAM_SIZE_MAX; - } - result = (IntStreamLSL) ((Object) new generated.java.util.stream.IntStreamLSL((Void) null, - /* state = */ generated.java.util.stream.IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ Engine.makeSymbolicIntArray(size), - /* length = */ size, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::ints(SecureRandom, long, int, int) -> IntStream - * Source: java/security/SecureRandom.main.lsl:484 - */ - public IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberBound) { - IntStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - int size = ((int) streamSize); - if (size < 0) { - throw new IllegalArgumentException(); - } - if (randomNumberOrigin >= randomNumberBound) { - throw new IllegalArgumentException(); - } - if (size > LibSLGlobals.RANDOM_STREAM_SIZE_MAX) { - size = LibSLGlobals.RANDOM_STREAM_SIZE_MAX; - } - result = (IntStreamLSL) ((Object) new generated.java.util.stream.IntStreamLSL((Void) null, - /* state = */ generated.java.util.stream.IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ _generateRandomIntegerArrayWithBounds(size, randomNumberOrigin, randomNumberBound), - /* length = */ size, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::longs(SecureRandom) -> LongStream - * Source: java/security/SecureRandom.main.lsl:505 - */ - public LongStream longs() { - LongStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (LongStreamLSL) ((Object) new generated.java.util.stream.LongStreamLSL((Void) null, - /* state = */ generated.java.util.stream.LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ Engine.makeSymbolicLongArray(LibSLGlobals.RANDOM_STREAM_SIZE_MAX), - /* length = */ LibSLGlobals.RANDOM_STREAM_SIZE_MAX, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::longs(SecureRandom, long) -> LongStream - * Source: java/security/SecureRandom.main.lsl:516 - */ - public LongStream longs(long streamSize) { - LongStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - int size = ((int) streamSize); - if (size < 0) { - throw new IllegalArgumentException(); - } - if (size > LibSLGlobals.RANDOM_STREAM_SIZE_MAX) { - size = LibSLGlobals.RANDOM_STREAM_SIZE_MAX; - } - result = (LongStreamLSL) ((Object) new generated.java.util.stream.LongStreamLSL((Void) null, - /* state = */ generated.java.util.stream.LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ Engine.makeSymbolicLongArray(size), - /* length = */ size, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::longs(SecureRandom, long, long) -> LongStream - * Source: java/security/SecureRandom.main.lsl:535 - */ - public LongStream longs(long randomNumberOrigin, long randomNumberBound) { - LongStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (randomNumberOrigin >= randomNumberBound) { - throw new IllegalArgumentException(); - } - result = (LongStreamLSL) ((Object) new generated.java.util.stream.LongStreamLSL((Void) null, - /* state = */ generated.java.util.stream.LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ _generateRandomLongArrayWithBounds(LibSLGlobals.RANDOM_STREAM_SIZE_MAX, randomNumberOrigin, randomNumberBound), - /* length = */ LibSLGlobals.RANDOM_STREAM_SIZE_MAX, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::longs(SecureRandom, long, long, long) -> LongStream - * Source: java/security/SecureRandom.main.lsl:549 - */ - public LongStream longs(long streamSize, long randomNumberOrigin, long randomNumberBound) { - LongStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - int size = ((int) streamSize); - if (size < 0) { - throw new IllegalArgumentException(); - } - if (randomNumberOrigin >= randomNumberBound) { - throw new IllegalArgumentException(); - } - if (size > LibSLGlobals.RANDOM_STREAM_SIZE_MAX) { - size = LibSLGlobals.RANDOM_STREAM_SIZE_MAX; - } - result = (LongStreamLSL) ((Object) new generated.java.util.stream.LongStreamLSL((Void) null, - /* state = */ generated.java.util.stream.LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ _generateRandomLongArrayWithBounds(size, randomNumberOrigin, randomNumberBound), - /* length = */ size, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::nextBoolean(SecureRandom) -> boolean - * Source: java/security/SecureRandom.main.lsl:570 - */ - public boolean nextBoolean() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = Engine.makeSymbolicBoolean(); - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::nextBytes(SecureRandom, array) -> void - * Source: java/security/SecureRandom.main.lsl:576 - */ - public void nextBytes(byte[] bytes) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int len = bytes.length; - final byte[] src = Engine.makeSymbolicByteArray(len); - LibSLRuntime.ArrayActions.copy(src, 0, bytes, 0, len); - } - } - - /** - * [FUNCTION] SecureRandomAutomaton::nextDouble(SecureRandom) -> double - * Source: java/security/SecureRandom.main.lsl:585 - */ - public double nextDouble() { - double result = 0.0d; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = Engine.makeSymbolicDouble(); - Engine.assume(0.0d <= result); - Engine.assume(result < 1.0d); - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::nextFloat(SecureRandom) -> float - * Source: java/security/SecureRandom.main.lsl:595 - */ - public float nextFloat() { - float result = 0.0f; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = Engine.makeSymbolicFloat(); - Engine.assume(0.0f <= result); - Engine.assume(result < 1.0f); - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::nextGaussian(SecureRandom) -> double - * Source: java/security/SecureRandom.main.lsl:605 - */ - public synchronized double nextGaussian() { - double result = 0.0d; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = Engine.makeSymbolicDouble(); - final boolean isNaN = result != result; - Engine.assume(!isNaN); - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::nextInt(SecureRandom) -> int - * Source: java/security/SecureRandom.main.lsl:614 - */ - public int nextInt() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = Engine.makeSymbolicInt(); - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::nextInt(SecureRandom, int) -> int - * Source: java/security/SecureRandom.main.lsl:621 - */ - public int nextInt(int bound) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (bound <= 0) { - throw new IllegalArgumentException(); - } - result = Engine.makeSymbolicInt(); - Engine.assume(0 <= result); - Engine.assume(result < bound); - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::nextLong(SecureRandom) -> long - * Source: java/security/SecureRandom.main.lsl:634 - */ - public long nextLong() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = Engine.makeSymbolicLong(); - } - return result; - } - - /** - * [FUNCTION] SecureRandomAutomaton::setSeed(SecureRandom, array) -> void - * Source: java/security/SecureRandom.main.lsl:640 - */ - public synchronized void setSeed(byte[] seed) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (seed == null) { - if (Engine.makeSymbolicBoolean()) { - throw new NullPointerException(); - } - } - } - } - - /** - * [FUNCTION] SecureRandomAutomaton::setSeed(SecureRandom, long) -> void - * Source: java/security/SecureRandom.main.lsl:651 - */ - public void setSeed(long seed) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(true); - } - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(SecureRandom.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/security/SecureRandomImpl.java b/approximations/src/main/java/generated/java/security/SecureRandomImpl.java new file mode 100644 index 00000000..a3b3e65b --- /dev/null +++ b/approximations/src/main/java/generated/java/security/SecureRandomImpl.java @@ -0,0 +1,258 @@ +package generated.java.security; + +import generated.java.util.RandomImpl; +import generated.runtime.LibSLGlobals; + +import java.io.Serial; +import java.io.Serializable; +import java.lang.IllegalArgumentException; +import java.lang.NullPointerException; +import java.lang.Object; +import java.lang.String; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Provider; +import java.security.SecureRandomSpi; +import java.security.Security; +import java.util.stream.DoubleStream; +import java.util.stream.IntStream; +import java.util.stream.LongStream; +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +@SuppressWarnings("unused") +@Approximate(java.security.SecureRandom.class) +public class SecureRandomImpl extends RandomImpl implements Serializable { + + @Serial + private static final long serialVersionUID = 4940670005562187L; + + private static final LibSLRuntime.Map defaultProvidersMap = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); + + static { + LibSLRuntime.Map dpMap = defaultProvidersMap; + Object o = LibSLGlobals.SOMETHING; + dpMap.set("SUN", o); + dpMap.set("SunRsaSign", o); + dpMap.set("SunJSSE", o); + dpMap.set("SunJCE", o); + dpMap.set("Apple", o); + dpMap.set("JdkLDAP", o); + dpMap.set("SunJGSS", o); + dpMap.set("SunSASL", o); + dpMap.set("SunPCSC", o); + dpMap.set("XMLDSig", o); + dpMap.set("SunPKCS11", o); + dpMap.set("SunEC", o); + dpMap.set("SunMSCAPI", o); + dpMap.set("OracleUcrypto", o); + dpMap.set("JdkSASL", o); + } + + public Provider provider; + + public String algorithm; + + public boolean defaultProvider; + + public SecureRandomImpl(Provider provider, String algorithm, boolean defaultProvider) { + this.provider = provider; + this.algorithm = algorithm; + this.defaultProvider = defaultProvider; + } + + public SecureRandomImpl() { + this(null, "SHA1PRNG", false); + } + + protected SecureRandomImpl(SecureRandomSpi secureRandomSpi, Provider provider) { + LibSLRuntime.error("Protected constructor call"); + } + + private SecureRandomImpl(SecureRandomSpi secureRandomSpi, Provider provider, String algorithm) { + LibSLRuntime.error("Private constructor call"); + } + + public SecureRandomImpl(byte[] seed) { + this(); + } + + private static boolean _isDefaultProvider(Provider curProvider) { + if (curProvider == null) + return false; + + String providerName = curProvider.getName(); + return defaultProvidersMap.hasKey(providerName); + } + + @SuppressWarnings("ConstantValue") + public static SecureRandomImpl getInstance(String _algorithm) throws NoSuchAlgorithmException { + Provider resultProvider = Engine.makeSymbolic(Provider.class); + String resultAlgorithm = Engine.makeSymbolic(String.class); + if (resultAlgorithm == null) + throw new NoSuchAlgorithmException(); + + int resultAlgorithmLength = resultAlgorithm.length(); + Engine.assume(resultAlgorithmLength > 0); + return new SecureRandomImpl(resultProvider, resultAlgorithm, _isDefaultProvider(resultProvider)); + } + + @SuppressWarnings("ConstantValue") + public static SecureRandomImpl getInstance(String _algorithm, Provider provider) throws NoSuchAlgorithmException { + if (provider == null) + throw new IllegalArgumentException(); + + // TODO: use arguments '_algorithm' and 'provider'? + Provider resultProvider = Engine.makeSymbolic(Provider.class); + String resultAlgorithm = Engine.makeSymbolic(String.class); + if (resultAlgorithm == null) + throw new NoSuchAlgorithmException(); + + int resultAlgorithmLength = resultAlgorithm.length(); + Engine.assume(resultAlgorithmLength > 0); + return new SecureRandomImpl(resultProvider, resultAlgorithm, _isDefaultProvider(resultProvider)); + } + + @SuppressWarnings("ConstantValue") + public static SecureRandomImpl getInstance(String _algorithm, String providerName) throws NoSuchAlgorithmException, NoSuchProviderException { + if (providerName == null || providerName.isEmpty()) { + throw new IllegalArgumentException(); + } + Provider resultProvider = Engine.makeSymbolic(Provider.class); + String resultAlgorithm = Engine.makeSymbolic(String.class); + if (resultProvider == null) + throw new NoSuchProviderException(); + if (resultAlgorithm == null) + throw new NoSuchAlgorithmException(); + int resultAlgorithmLength = resultAlgorithm.length(); + Engine.assume(resultAlgorithmLength > 0); + return new SecureRandomImpl(resultProvider, resultAlgorithm, _isDefaultProvider(resultProvider)); + } + + @SuppressWarnings("ConstantValue") + public static SecureRandomImpl getInstanceStrong() throws java.security.NoSuchAlgorithmException { + String property = Security.getProperty("securerandom.strongAlgorithms"); + if (property == null) + throw new NoSuchAlgorithmException(); + if (property.isEmpty()) + throw new NoSuchAlgorithmException(); + Provider resultProvider = Engine.makeSymbolic(Provider.class); + String resultAlgorithm = Engine.makeSymbolic(String.class); + if (resultAlgorithm == null) + throw new NoSuchAlgorithmException(); + + return new SecureRandomImpl(resultProvider, resultAlgorithm, _isDefaultProvider(resultProvider)); + } + + public static byte[] getSeed(int numBytes) { + if (numBytes < 0) + throw new IllegalArgumentException(); + + return Engine.makeSymbolicByteArray(numBytes); + } + + public DoubleStream doubles() { + return super.doubles(); + } + + public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound) { + return super.doubles(randomNumberOrigin, randomNumberBound); + } + + public DoubleStream doubles(long streamSize) { + return super.doubles(streamSize); + } + + public DoubleStream doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) { + return super.doubles(streamSize, randomNumberOrigin, randomNumberBound); + } + + public byte[] generateSeed(int numBytes) { + if (numBytes < 0) + throw new IllegalArgumentException(); + + return Engine.makeSymbolicByteArray(numBytes); + } + + public String getAlgorithm() { + return this.algorithm; + } + + public Provider getProvider() { + return this.provider; + } + + public IntStream ints() { + return super.ints(); + } + + public IntStream ints(int randomNumberOrigin, int randomNumberBound) { + return super.ints(randomNumberOrigin, randomNumberBound); + } + + public IntStream ints(long streamSize) { + return super.ints(streamSize); + } + + public IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberBound) { + return super.ints(streamSize, randomNumberOrigin, randomNumberBound); + } + + public LongStream longs() { + return super.longs(); + } + + public LongStream longs(long streamSize) { + return super.longs(streamSize); + } + + public LongStream longs(long randomNumberOrigin, long randomNumberBound) { + return super.longs(randomNumberOrigin, randomNumberBound); + } + + public LongStream longs(long streamSize, long randomNumberOrigin, long randomNumberBound) { + return super.longs(streamSize, randomNumberOrigin, randomNumberBound); + } + + public boolean nextBoolean() { + return super.nextBoolean(); + } + + public void nextBytes(byte[] bytes) { + super.nextBytes(bytes); + } + + public double nextDouble() { + return super.nextDouble(); + } + + public float nextFloat() { + return super.nextFloat(); + } + + public synchronized double nextGaussian() { + return super.nextGaussian(); + } + + public int nextInt() { + return super.nextInt(); + } + + public int nextInt(int bound) { + return super.nextInt(bound); + } + + public long nextLong() { + return super.nextLong(); + } + + public synchronized void setSeed(byte[] seed) { + if (seed == null && Engine.makeSymbolicBoolean()) + throw new NullPointerException(); + } + + public void setSeed(long seed) { + super.setSeed(seed); + } +} diff --git a/approximations/src/main/java/generated/java/util/AbstractCollectionImpl.java b/approximations/src/main/java/generated/java/util/AbstractCollectionImpl.java new file mode 100644 index 00000000..a438b323 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/AbstractCollectionImpl.java @@ -0,0 +1,65 @@ +package generated.java.util; + +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +import java.util.Arrays; +import java.util.Collection; +import java.util.ConcurrentModificationException; +import java.util.function.IntFunction; + +@Approximate(java.util.AbstractCollection.class) +public abstract class AbstractCollectionImpl implements Collection { + + public transient int modCount; + + public AbstractCollectionImpl(int modCount) { + this.modCount = modCount; + } + + abstract protected Object[] _mapToArray(); + + protected void _checkForModification(int expectedModCount) { + if (this.modCount != expectedModCount) + throw new ConcurrentModificationException(); + } + + abstract public int _size(); + + @NotNull + public Object[] _toArray() { + return _mapToArray(); + } + + @SuppressWarnings("unchecked") + private T[] _toArray(T[] array, int size) { + Object[] contents = _mapToArray(); + Engine.assume(size == contents.length); + + if (array.length < size) + return (T[]) Arrays.copyOf(contents, size, array.getClass()); + + LibSLRuntime.ArrayActions.copy(contents, 0, array, 0, size); + if (array.length > size) { + array[size] = null; + } + return array; + } + + public T[] _toArray(IntFunction generator) { + int size = _size(); + T[] array = generator.apply(size); + + return _toArray(array, size); + } + + @NotNull + public T[] toArray(@NotNull T[] array) { + int size = _size(); + return _toArray(array, size); + } + + abstract public String toString(); +} diff --git a/approximations/src/main/java/generated/java/util/AbstractIteratorImpl.java b/approximations/src/main/java/generated/java/util/AbstractIteratorImpl.java new file mode 100644 index 00000000..143f5f16 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/AbstractIteratorImpl.java @@ -0,0 +1,24 @@ +package generated.java.util; + +import org.jacodb.approximation.annotation.Approximate; +import stub.java.util.AbstractIterator; + +import java.util.ConcurrentModificationException; +import java.util.Iterator; + +@Approximate(AbstractIterator.class) +public abstract class AbstractIteratorImpl implements Iterator { + + public int expectedModCount; + + public AbstractIteratorImpl(int expectedModCount) { + this.expectedModCount = expectedModCount; + } + + abstract protected int _parentModCount(); + + protected void _checkForModification() { + if (_parentModCount() != this.expectedModCount) + throw new ConcurrentModificationException(); + } +} diff --git a/approximations/src/main/java/generated/java/util/AbstractMap_SimpleEntry.java b/approximations/src/main/java/generated/java/util/AbstractMap_SimpleEntry.java deleted file mode 100644 index 65a3ead2..00000000 --- a/approximations/src/main/java/generated/java/util/AbstractMap_SimpleEntry.java +++ /dev/null @@ -1,178 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/AbstractMap.lsl:23 -// - java/util/AbstractMap.SimpleEntry.lsl:19 -// -package generated.java.util; - -import java.io.Serializable; -import java.lang.Object; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Map; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * AbstractMap_SimpleEntryAutomaton for AbstractMap_SimpleEntry ~> java.util.AbstractMap_SimpleEntry - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.AbstractMap_SimpleEntry.class) -public class AbstractMap_SimpleEntry implements LibSLRuntime.Automaton, Serializable, Map.Entry { - private static final long serialVersionUID = -8499721149061103585L; - - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public Object key; - - public Object value; - - @LibSLRuntime.AutomatonConstructor - public AbstractMap_SimpleEntry(Void __$lsl_token, final byte p0, final Object p1, - final Object p2) { - this.__$lsl_state = p0; - this.key = p1; - this.value = p2; - } - - @LibSLRuntime.AutomatonConstructor - public AbstractMap_SimpleEntry(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, null, null); - } - - /** - * [CONSTRUCTOR] AbstractMap_SimpleEntryAutomaton::(AbstractMap_SimpleEntry, Map_Entry) -> void - * Source: java/util/AbstractMap.SimpleEntry.lsl:53 - */ - public AbstractMap_SimpleEntry(Map.Entry entry) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.key = entry.getKey(); - this.value = entry.getValue(); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] AbstractMap_SimpleEntryAutomaton::(AbstractMap_SimpleEntry, Object, Object) -> void - * Source: java/util/AbstractMap.SimpleEntry.lsl:60 - */ - public AbstractMap_SimpleEntry(Object key, Object value) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - key = key; - value = value; - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [FUNCTION] AbstractMap_SimpleEntryAutomaton::equals(AbstractMap_SimpleEntry, Object) -> boolean - * Source: java/util/AbstractMap.SimpleEntry.lsl:71 - */ - public boolean equals(Object other) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (other == this) { - result = true; - } else { - result = (other instanceof Map.Entry); - if (result) { - final Map.Entry oEntry = ((Map.Entry) other); - final Object otherKey = oEntry.getKey(); - final Object otherValue = oEntry.getValue(); - result = LibSLRuntime.equals(this.key, otherKey) && LibSLRuntime.equals(this.value, otherValue); - } - } - } - return result; - } - - /** - * [FUNCTION] AbstractMap_SimpleEntryAutomaton::getKey(AbstractMap_SimpleEntry) -> Object - * Source: java/util/AbstractMap.SimpleEntry.lsl:91 - */ - public Object getKey() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.key; - } - return result; - } - - /** - * [FUNCTION] AbstractMap_SimpleEntryAutomaton::getValue(AbstractMap_SimpleEntry) -> Object - * Source: java/util/AbstractMap.SimpleEntry.lsl:97 - */ - public Object getValue() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - } - return result; - } - - /** - * [FUNCTION] AbstractMap_SimpleEntryAutomaton::hashCode(AbstractMap_SimpleEntry) -> int - * Source: java/util/AbstractMap.SimpleEntry.lsl:103 - */ - public int hashCode() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = LibSLRuntime.hashCode(this.key) ^ LibSLRuntime.hashCode(this.value); - } - return result; - } - - /** - * [FUNCTION] AbstractMap_SimpleEntryAutomaton::setValue(AbstractMap_SimpleEntry, Object) -> Object - * Source: java/util/AbstractMap.SimpleEntry.lsl:109 - */ - public Object setValue(Object value) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = value; - value = value; - } - return result; - } - - /** - * [FUNCTION] AbstractMap_SimpleEntryAutomaton::toString(AbstractMap_SimpleEntry) -> String - * Source: java/util/AbstractMap.SimpleEntry.lsl:116 - */ - public String toString() { - String result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = LibSLRuntime.toString(this.key).concat("=").concat(LibSLRuntime.toString(this.value)); - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(AbstractMap_SimpleEntry.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/AbstractSpliteratorImpl.java b/approximations/src/main/java/generated/java/util/AbstractSpliteratorImpl.java new file mode 100644 index 00000000..9af3cd78 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/AbstractSpliteratorImpl.java @@ -0,0 +1,75 @@ +package generated.java.util; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; + +import java.util.ConcurrentModificationException; +import java.util.Spliterator; +import java.util.function.Consumer; + +@Approximate(java.util.Spliterators.AbstractSpliterator.class) +public abstract class AbstractSpliteratorImpl implements Spliterator { + + public int index; + + public int fence; + + public int expectedModCount; + + public AbstractSpliteratorImpl(int index, int fence, int expectedModCount) { + Engine.assume(index >= 0); + this.index = index; + this.fence = fence; + this.expectedModCount = expectedModCount; + } + + abstract protected AbstractSpliteratorImpl _create(int index, int fence); + + abstract protected int _parentModCount(); + + protected final void _eval() { + this.expectedModCount = _parentModCount(); + } + + abstract protected int _storageSize(); + + protected int _getFence() { + if (this.fence < 0) { + _eval(); + this.fence = _storageSize(); + Engine.assume(this.fence >= 0); + } + + return this.fence; + } + + protected void _checkForModification() { + if (_parentModCount() != expectedModCount) + throw new ConcurrentModificationException(); + } + + public abstract int characteristics(); + + public long estimateSize() { + return getExactSizeIfKnown(); + } + + public abstract void forEachRemaining(Consumer userAction); + + public long getExactSizeIfKnown() { + return _getFence() - this.index; + } + + public abstract boolean tryAdvance(Consumer userAction); + + public AbstractSpliteratorImpl trySplit() { + int hi = _getFence(); + int lo = this.index; + int mid = (lo + hi) >>> 1; + if (lo >= mid) + return null; + + this.index = mid; + return _create(lo, mid); + } +} diff --git a/approximations/src/main/java/generated/java/util/ArrayList.java b/approximations/src/main/java/generated/java/util/ArrayList.java deleted file mode 100644 index 3d20bbd6..00000000 --- a/approximations/src/main/java/generated/java/util/ArrayList.java +++ /dev/null @@ -1,1119 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/ArrayList.lsl:21 -// - java/util/ArrayList.main.lsl:18 -// -package generated.java.util; - -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.lang.Cloneable; -import java.lang.Comparable; -import java.lang.IllegalArgumentException; -import java.lang.IndexOutOfBoundsException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Collection; -import java.util.Comparator; -import java.util.ConcurrentModificationException; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.RandomAccess; -import java.util.Spliterator; -import java.util.function.Consumer; -import java.util.function.IntFunction; -import java.util.function.Predicate; -import java.util.function.UnaryOperator; -import java.util.stream.Stream; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import org.usvm.api.SymbolicList; -import runtime.LibSLRuntime; -import stub.java.util.stream.StreamLSL; - -/** - * ArrayListAutomaton for ArrayList ~> java.util.ArrayList - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.util.ArrayList.class) -public class ArrayList implements LibSLRuntime.Automaton, List, RandomAccess, Cloneable, Serializable { - private static final long serialVersionUID = 8683452581122892189L; - - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public SymbolicList storage; - - public transient int modCount; - - @LibSLRuntime.AutomatonConstructor - public ArrayList(Void __$lsl_token, final byte p0, final SymbolicList p1, - final int p2) { - this.__$lsl_state = p0; - this.storage = p1; - this.modCount = p2; - } - - @LibSLRuntime.AutomatonConstructor - public ArrayList(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, null, 0); - } - - /** - * [CONSTRUCTOR] ArrayListAutomaton::(ArrayList) -> void - * Source: java/util/ArrayList.main.lsl:536 - */ - public ArrayList() { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.storage = Engine.makeSymbolicList(); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] ArrayListAutomaton::(ArrayList, Collection) -> void - * Source: java/util/ArrayList.main.lsl:542 - */ - public ArrayList(Collection c) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - if (c == null) { - throw new NullPointerException(); - } - this.storage = Engine.makeSymbolicList(); - _addAllElements(0, c); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] ArrayListAutomaton::(ArrayList, int) -> void - * Source: java/util/ArrayList.main.lsl:553 - */ - public ArrayList(int initialCapacity) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - if (initialCapacity < 0) { - throw new IllegalArgumentException(); - } - this.storage = Engine.makeSymbolicList(); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] ArrayListAutomaton::_checkValidIndex(int, int) -> void - * Source: java/util/ArrayList.main.lsl:86 - */ - public void _checkValidIndex(int index, int length) { - /* body */ { - if ((index < 0) || (length <= index)) { - throw new IndexOutOfBoundsException(); - } - } - } - - /** - * [SUBROUTINE] ArrayListAutomaton::_rangeCheckForAdd(int) -> void - * Source: java/util/ArrayList.main.lsl:98 - */ - public void _rangeCheckForAdd(int index) { - /* body */ { - if ((index > this.storage.size()) || (index < 0)) { - throw new IndexOutOfBoundsException(); - } - } - } - - /** - * [SUBROUTINE] ArrayListAutomaton::_addAllElements(int, Collection) -> boolean - * Source: java/util/ArrayList.main.lsl:110 - */ - public boolean _addAllElements(int index, Collection c) { - boolean result = false; - /* body */ { - final int oldLength = this.storage.size(); - if ((c != null && c.getClass() == java.util.ArrayList.class)) { - final SymbolicList otherStorage = ((ArrayList) ((Object) c)).storage; - final int otherLength = otherStorage.size(); - Engine.assume(otherStorage != null); - Engine.assume(otherLength >= 0); - int i = 0; - for (i = 0; i < otherLength; i += 1) { - final Object item = otherStorage.get(i); - this.storage.insert(index, item); - index += 1; - } - ; - } else { - final Iterator iter = c.iterator(); - while (iter.hasNext()) { - final Object item = iter.next(); - this.storage.insert(index, item); - index += 1; - } - ; - } - result = oldLength != this.storage.size(); - if (result) { - this.modCount += 1; - } - } - return result; - } - - /** - * [SUBROUTINE] ArrayListAutomaton::_subListRangeCheck(int, int, int) -> void - * Source: java/util/ArrayList.main.lsl:160 - */ - public void _subListRangeCheck(int fromIndex, int toIndex, int size) { - /* body */ { - if (fromIndex < 0) { - throw new IndexOutOfBoundsException(); - } - if (toIndex > size) { - throw new IndexOutOfBoundsException(); - } - if (fromIndex > toIndex) { - throw new IllegalArgumentException(); - } - } - } - - /** - * [SUBROUTINE] ArrayListAutomaton::_checkForComodification(int) -> void - * Source: java/util/ArrayList.main.lsl:184 - */ - public void _checkForComodification(int expectedModCount) { - /* body */ { - if (this.modCount != expectedModCount) { - throw new ConcurrentModificationException(); - } - } - } - - /** - * [SUBROUTINE] ArrayListAutomaton::_deleteElement(int) -> Object - * Source: java/util/ArrayList.main.lsl:191 - */ - public Object _deleteElement(int index) { - Object result = null; - /* body */ { - _checkValidIndex(index, this.storage.size()); - result = this.storage.get(index); - this.storage.remove(index); - this.modCount += 1; - } - return result; - } - - /** - * [SUBROUTINE] ArrayListAutomaton::_addElement(int, Object) -> void - * Source: java/util/ArrayList.main.lsl:202 - */ - public void _addElement(int index, Object element) { - /* body */ { - _rangeCheckForAdd(index); - this.storage.insert(index, element); - this.modCount += 1; - } - } - - /** - * [SUBROUTINE] ArrayListAutomaton::_setElement(int, Object) -> Object - * Source: java/util/ArrayList.main.lsl:212 - */ - private Object _setElement(int index, Object element) { - Object result = null; - /* body */ { - _checkValidIndex(index, this.storage.size()); - result = this.storage.get(index); - this.storage.set(index, element); - } - return result; - } - - /** - * [SUBROUTINE] ArrayListAutomaton::_replaceAllRange(UnaryOperator, int, int) -> void - * Source: java/util/ArrayList.main.lsl:227 - */ - public void _replaceAllRange(UnaryOperator op, int i, int end) { - /* body */ { - final int expectedModCount = this.modCount; - while ((this.modCount == expectedModCount) && (i < end)) { - final Object oldItem = this.storage.get(i); - final Object newItem = op.apply(oldItem); - this.storage.set(i, newItem); - i += 1; - } - ; - _checkForComodification(expectedModCount); - } - } - - /** - * [SUBROUTINE] ArrayListAutomaton::_removeIf(Predicate, int, int) -> boolean - * Source: java/util/ArrayList.main.lsl:249 - */ - public boolean _removeIf(Predicate filter, int start, int end) { - boolean result = false; - /* body */ { - if (filter == null) { - throw new NullPointerException(); - } - final int oldLength = this.storage.size(); - final int expectedModCount = this.modCount; - Engine.assume(start <= end); - int i = 0; - for (i = end - 1; i > start; i += -1) { - final Object item = this.storage.get(i); - if (filter.test(item)) { - this.storage.remove(i); - } - } - ; - _checkForComodification(expectedModCount); - result = oldLength != this.storage.size(); - } - return result; - } - - /** - * [SUBROUTINE] ArrayListAutomaton::_equalsRange(List, int, int) -> boolean - * Source: java/util/ArrayList.main.lsl:278 - */ - public boolean _equalsRange(List other, int from, int to) { - boolean result = false; - /* body */ { - result = true; - int i = from; - SymbolicList otherStorage = null; - if ((other != null && other.getClass() == java.util.ArrayList.class)) { - otherStorage = ((ArrayList) ((Object) other)).storage; - result = to == otherStorage.size(); - if (result) { - while (result && (i < to)) { - final Object a = otherStorage.get(i); - final Object b = this.storage.get(i); - result = LibSLRuntime.equals(a, b); - i += 1; - } - ; - } - } else { - if ((other != null && other.getClass() == stub.java.util.ArrayList_SubList.class)) { - final ArrayList otherRoot = ((ArrayList_SubList) ((Object) other)).root; - otherStorage = ((ArrayList) ((Object) otherRoot)).storage; - result = to == ((ArrayList_SubList) ((Object) other)).length; - if (result) { - while (result && (i < to)) { - final Object a = otherStorage.get(i); - final Object b = this.storage.get(i); - result = LibSLRuntime.equals(a, b); - i += 1; - } - ; - } - } else { - final Iterator iter = other.iterator(); - while (result && (i < to) && iter.hasNext()) { - final Object a = iter.next(); - final Object b = this.storage.get(i); - result = LibSLRuntime.equals(a, b); - i += 1; - } - ; - result &= !iter.hasNext(); - } - } - } - return result; - } - - /** - * [SUBROUTINE] ArrayListAutomaton::_makeStream(boolean) -> Stream - * Source: java/util/ArrayList.main.lsl:343 - */ - private Stream _makeStream(boolean parallel) { - Stream result = null; - /* body */ { - final int count = this.storage.size(); - final Object[] items = new Object[count]; - int i = 0; - for (i = 0; i < count; i += 1) { - items[i] = this.storage.get(i); - } - ; - result = (StreamLSL) ((Object) new generated.java.util.stream.StreamLSL((Void) null, - /* state = */ generated.java.util.stream.StreamLSL.__$lsl_States.Initialized, - /* storage = */ items, - /* length = */ count, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ parallel, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [SUBROUTINE] ArrayListAutomaton::_batchRemove(Collection, boolean, int, int) -> boolean - * Source: java/util/ArrayList.main.lsl:370 - */ - public boolean _batchRemove(Collection c, boolean complement, int start, int end) { - boolean result = false; - /* body */ { - if (c == null) { - throw new NullPointerException(); - } - final int oldLength = this.storage.size(); - if ((oldLength == 0) || (start >= end)) { - result = false; - } else { - final int otherLength = c.size(); - if (otherLength == 0) { - if (complement) { - result = true; - this.storage = Engine.makeSymbolicList(); - this.modCount += 1; - } else { - result = false; - } - } else { - Engine.assume(otherLength > 0); - int i = 0; - start -= 1; - end -= 1; - if ((c != null && c.getClass() == java.util.ArrayList.class)) { - final SymbolicList otherStorage = ((ArrayList) ((Object) c)).storage; - Engine.assume(otherStorage != null); - for (i = end; i > start; i += -1) { - final Object item = this.storage.get(i); - if ((LibSLRuntime.ListActions.find(otherStorage, item, 0, this.storage.size()) == -1) == complement) { - _deleteElement(i); - } - } - ; - } else { - for (i = end; i > start; i += -1) { - final Object item = this.storage.get(i); - if (c.contains(item) != complement) { - _deleteElement(i); - } - } - ; - } - result = oldLength != this.storage.size(); - } - } - } - return result; - } - - /** - * [SUBROUTINE] ArrayListAutomaton::_do_sort(int, int, Comparator) -> void - * Source: java/util/ArrayList.main.lsl:443 - */ - public void _do_sort(int start, int end, Comparator c) { - /* body */ { - if (start < end) { - final int expectedModCount = this.modCount; - Engine.assume(start >= 0); - Engine.assume(end > 0); - final int outerLimit = end - 1; - int innerLimit = 0; - int i = 0; - int j = 0; - if (c == null) { - for (i = start; i < outerLimit; i += 1) { - innerLimit = (end - i) - 1; - for (j = start; j < innerLimit; j += 1) { - final int idxA = j; - final int idxB = j + 1; - final Object a = this.storage.get(idxA); - final Object b = this.storage.get(idxB); - if (((Comparable) a).compareTo(b) > 0) { - this.storage.set(idxA, b); - this.storage.set(idxB, a); - } - } - ; - } - ; - } else { - for (i = start; i < outerLimit; i += 1) { - innerLimit = (end - i) - 1; - for (j = start; j < innerLimit; j += 1) { - final int idxA = j; - final int idxB = j + 1; - final Object a = this.storage.get(idxA); - final Object b = this.storage.get(idxB); - if (c.compare(a, b) > 0) { - this.storage.set(idxA, b); - this.storage.set(idxB, a); - } - } - ; - } - ; - } - _checkForComodification(expectedModCount); - } - this.modCount += 1; - } - } - - /** - * [FUNCTION] ArrayListAutomaton::add(ArrayList, Object) -> boolean - * Source: java/util/ArrayList.main.lsl:566 - */ - public boolean add(Object e) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.storage.insert(this.storage.size(), e); - this.modCount += 1; - result = true; - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::add(ArrayList, int, Object) -> void - * Source: java/util/ArrayList.main.lsl:576 - */ - public void add(int index, Object element) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _addElement(index, element); - } - } - - /** - * [FUNCTION] ArrayListAutomaton::addAll(ArrayList, Collection) -> boolean - * Source: java/util/ArrayList.main.lsl:582 - */ - public boolean addAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _addAllElements(this.storage.size(), c); - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::addAll(ArrayList, int, Collection) -> boolean - * Source: java/util/ArrayList.main.lsl:588 - */ - public boolean addAll(int index, Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _rangeCheckForAdd(index); - result = _addAllElements(index, c); - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::clear(ArrayList) -> void - * Source: java/util/ArrayList.main.lsl:595 - */ - public void clear() { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.storage = Engine.makeSymbolicList(); - this.modCount += 1; - } - } - - /** - * [FUNCTION] ArrayListAutomaton::clone(ArrayList) -> Object - * Source: java/util/ArrayList.main.lsl:602 - */ - public Object clone() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final SymbolicList storageCopy = Engine.makeSymbolicList(); - this.storage.copy(storageCopy, 0, 0, this.storage.size()); - result = (java.util.ArrayList) ((Object) new ArrayList((Void) null, - /* state = */ ArrayList.__$lsl_States.Initialized, - /* storage = */ storageCopy, - /* modCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::contains(ArrayList, Object) -> boolean - * Source: java/util/ArrayList.main.lsl:613 - */ - public boolean contains(Object o) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = LibSLRuntime.ListActions.find(this.storage, o, 0, this.storage.size()) != -1; - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::containsAll(ArrayList, Collection) -> boolean - * Source: java/util/ArrayList.main.lsl:620 - */ - public boolean containsAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = true; - if ((c != null && c.getClass() == java.util.ArrayList.class)) { - final SymbolicList otherStorage = ((ArrayList) ((Object) c)).storage; - Engine.assume(otherStorage != null); - final int otherLength = otherStorage.size(); - Engine.assume(otherLength >= 0); - int i = 0; - while (result && (i < otherLength)) { - final Object item = otherStorage.get(i); - result = LibSLRuntime.ListActions.find(this.storage, item, 0, this.storage.size()) != -1; - i += 1; - } - ; - } else { - final Iterator iter = c.iterator(); - while (result && iter.hasNext()) { - final Object item = iter.next(); - result = LibSLRuntime.ListActions.find(this.storage, item, 0, this.storage.size()) != -1; - } - ; - } - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::ensureCapacity(ArrayList, int) -> void - * Source: java/util/ArrayList.main.lsl:663 - */ - public void ensureCapacity(int minCapacity) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.modCount += 1; - } - } - - /** - * [FUNCTION] ArrayListAutomaton::equals(ArrayList, Object) -> boolean - * Source: java/util/ArrayList.main.lsl:670 - */ - public boolean equals(Object other) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (other == this) { - result = true; - } else { - if ((other != null && other.getClass() == java.util.ArrayList.class)) { - final int expectedModCount = this.modCount; - final int otherExpectedModCount = ((ArrayList) ((Object) other)).modCount; - final SymbolicList otherStorage = ((ArrayList) ((Object) other)).storage; - if (this.storage.size() == otherStorage.size()) { - result = LibSLRuntime.equals(this.storage, otherStorage); - } else { - result = false; - } - ((ArrayList) ((Object) other))._checkForComodification(otherExpectedModCount); - _checkForComodification(expectedModCount); - } else { - result = false; - } - } - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::forEach(ArrayList, Consumer) -> void - * Source: java/util/ArrayList.main.lsl:700 - */ - public void forEach(Consumer _action) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - final int expectedModCount = this.modCount; - int i = 0; - while ((this.modCount == expectedModCount) && (i < this.storage.size())) { - final Object item = this.storage.get(i); - _action.accept(item); - i += 1; - } - ; - _checkForComodification(expectedModCount); - } - } - - /** - * [FUNCTION] ArrayListAutomaton::get(ArrayList, int) -> Object - * Source: java/util/ArrayList.main.lsl:725 - */ - public Object get(int index) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _checkValidIndex(index, this.storage.size()); - result = this.storage.get(index); - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::hashCode(ArrayList) -> int - * Source: java/util/ArrayList.main.lsl:733 - */ - public int hashCode() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = LibSLRuntime.hashCode(this.storage); - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::indexOf(ArrayList, Object) -> int - * Source: java/util/ArrayList.main.lsl:739 - */ - public int indexOf(Object o) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = LibSLRuntime.ListActions.find(this.storage, o, 0, this.storage.size()); - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::isEmpty(ArrayList) -> boolean - * Source: java/util/ArrayList.main.lsl:745 - */ - public boolean isEmpty() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.storage.size() == 0; - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::iterator(ArrayList) -> Iterator - * Source: java/util/ArrayList.main.lsl:751 - */ - public Iterator iterator() { - Iterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (stub.java.util.ArrayList_ListItr) ((Object) new ArrayList_ListItr((Void) null, - /* state = */ ArrayList_ListItr.__$lsl_States.Initialized, - /* parent = */ this, - /* cursor = */ 0, - /* expectedModCount = */ this.modCount, - /* lastRet = */ -1 - )); - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::lastIndexOf(ArrayList, Object) -> int - * Source: java/util/ArrayList.main.lsl:761 - */ - public int lastIndexOf(Object o) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = -1; - final int size = this.storage.size(); - if (size != 0) { - Engine.assume(size > 0); - final SymbolicList items = this.storage; - int i = 0; - for (i = size - 1; i > -1; i += -1) { - final Object e = items.get(i); - if (LibSLRuntime.equals(o, e)) { - result = i; - break; - } - } - ; - } - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::listIterator(ArrayList) -> ListIterator - * Source: java/util/ArrayList.main.lsl:792 - */ - public ListIterator listIterator() { - ListIterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (stub.java.util.ArrayList_ListItr) ((Object) new ArrayList_ListItr((Void) null, - /* state = */ ArrayList_ListItr.__$lsl_States.Initialized, - /* parent = */ this, - /* cursor = */ 0, - /* expectedModCount = */ this.modCount, - /* lastRet = */ -1 - )); - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::listIterator(ArrayList, int) -> ListIterator - * Source: java/util/ArrayList.main.lsl:802 - */ - public ListIterator listIterator(int index) { - ListIterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _rangeCheckForAdd(index); - result = (stub.java.util.ArrayList_ListItr) ((Object) new ArrayList_ListItr((Void) null, - /* state = */ ArrayList_ListItr.__$lsl_States.Initialized, - /* parent = */ this, - /* cursor = */ index, - /* expectedModCount = */ this.modCount, - /* lastRet = */ -1 - )); - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::parallelStream(ArrayList) -> Stream - * Source: java/util/ArrayList.main.lsl:815 - */ - public Stream parallelStream() { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _makeStream(true); - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::remove(ArrayList, Object) -> boolean - * Source: java/util/ArrayList.main.lsl:821 - */ - public boolean remove(Object o) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int index = LibSLRuntime.ListActions.find(this.storage, o, 0, this.storage.size()); - result = index != -1; - if (result) { - _deleteElement(index); - } - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::remove(ArrayList, int) -> Object - * Source: java/util/ArrayList.main.lsl:830 - */ - public Object remove(int index) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _deleteElement(index); - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::removeAll(ArrayList, Collection) -> boolean - * Source: java/util/ArrayList.main.lsl:836 - */ - public boolean removeAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _batchRemove(c, false, 0, this.storage.size()); - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::removeIf(ArrayList, Predicate) -> boolean - * Source: java/util/ArrayList.main.lsl:842 - */ - public boolean removeIf(Predicate filter) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _removeIf(filter, 0, this.storage.size()); - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::replaceAll(ArrayList, UnaryOperator) -> void - * Source: java/util/ArrayList.main.lsl:848 - */ - public void replaceAll(UnaryOperator op) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (op == null) { - throw new NullPointerException(); - } - _replaceAllRange(op, 0, this.storage.size()); - this.modCount += 1; - } - } - - /** - * [FUNCTION] ArrayListAutomaton::retainAll(ArrayList, Collection) -> boolean - * Source: java/util/ArrayList.main.lsl:858 - */ - public boolean retainAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _batchRemove(c, true, 0, this.storage.size()); - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::set(ArrayList, int, Object) -> Object - * Source: java/util/ArrayList.main.lsl:864 - */ - public Object set(int index, Object element) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _setElement(index, element); - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::size(ArrayList) -> int - * Source: java/util/ArrayList.main.lsl:870 - */ - public int size() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.storage.size(); - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::sort(ArrayList, Comparator) -> void - * Source: java/util/ArrayList.main.lsl:876 - */ - public void sort(Comparator c) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _do_sort(0, this.storage.size(), c); - } - } - - /** - * [FUNCTION] ArrayListAutomaton::spliterator(ArrayList) -> Spliterator - * Source: java/util/ArrayList.main.lsl:882 - */ - public Spliterator spliterator() { - Spliterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (stub.java.util.ArrayList_Spliterator) ((Object) new ArrayList_Spliterator((Void) null, - /* state = */ ArrayList_Spliterator.__$lsl_States.Initialized, - /* parent = */ this, - /* index = */ 0, - /* fence = */ -1, - /* expectedModCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::stream(ArrayList) -> Stream - * Source: java/util/ArrayList.main.lsl:891 - */ - public Stream stream() { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _makeStream(false); - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::subList(ArrayList, int, int) -> List - * Source: java/util/ArrayList.main.lsl:897 - */ - public List subList(int fromIndex, int toIndex) { - List result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _subListRangeCheck(fromIndex, toIndex, this.storage.size()); - result = (stub.java.util.ArrayList_SubList) ((Object) new ArrayList_SubList((Void) null, - /* state = */ ArrayList_SubList.__$lsl_States.Initialized, - /* root = */ this, - /* parentList = */ null, - /* offset = */ fromIndex, - /* length = */ toIndex - fromIndex, - /* modCount = */ this.modCount - )); - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::toArray(ArrayList) -> array - * Source: java/util/ArrayList.main.lsl:911 - */ - public Object[] toArray() { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int len = this.storage.size(); - result = new Object[len]; - int i = 0; - for (i = 0; i < len; i += 1) { - result[i] = this.storage.get(i); - } - ; - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::toArray(ArrayList, IntFunction) -> array - * Source: java/util/ArrayList.main.lsl:931 - */ - public Object[] toArray(IntFunction generator) { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final Object[] a = ((Object[]) generator.apply(0)); - final int aLen = a.length; - final int len = this.storage.size(); - result = new Object[len]; - int i = 0; - for (i = 0; i < len; i += 1) { - result[i] = this.storage.get(i); - } - ; - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::toArray(ArrayList, array) -> array - * Source: java/util/ArrayList.main.lsl:949 - */ - public Object[] toArray(Object[] a) { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int aLen = a.length; - final int len = this.storage.size(); - if (aLen < len) { - a = new Object[len]; - } - result = a; - int i = 0; - for (i = 0; i < len; i += 1) { - result[i] = this.storage.get(i); - } - ; - if (aLen > len) { - result[len] = null; - } - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::toString(ArrayList) -> String - * Source: java/util/ArrayList.main.lsl:972 - */ - public String toString() { - String result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = LibSLRuntime.toString(this.storage); - } - return result; - } - - /** - * [FUNCTION] ArrayListAutomaton::trimToSize(ArrayList) -> void - * Source: java/util/ArrayList.main.lsl:978 - */ - public void trimToSize() { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.modCount += 1; - } - } - - /** - * [FUNCTION] ArrayListAutomaton::writeObject(ArrayList, ObjectOutputStream) -> void - * Source: java/util/ArrayList.main.lsl:987 - */ - private void writeObject(ObjectOutputStream s) throws java.io.IOException { - /* body */ { - LibSLRuntime.not_implemented(/* no serialization support yet */); - } - } - - /** - * [FUNCTION] ArrayListAutomaton::readObject(ArrayList, ObjectInputStream) -> void - * Source: java/util/ArrayList.main.lsl:995 - */ - private void readObject(ObjectInputStream s) throws java.io.IOException, - java.lang.ClassNotFoundException { - /* body */ { - LibSLRuntime.not_implemented(/* no serialization support yet */); - } - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(ArrayList.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/ArrayList_ListItr.java b/approximations/src/main/java/generated/java/util/ArrayList_ListItr.java deleted file mode 100644 index f0c7655c..00000000 --- a/approximations/src/main/java/generated/java/util/ArrayList_ListItr.java +++ /dev/null @@ -1,264 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/ArrayList.lsl:36 -// - java/util/ArrayList.ListIterator.lsl:16 -// -package generated.java.util; - -import java.lang.IllegalStateException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ConcurrentModificationException; -import java.util.ListIterator; -import java.util.NoSuchElementException; -import java.util.function.Consumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import org.usvm.api.SymbolicList; -import runtime.LibSLRuntime; - -/** - * ArrayList_ListIteratorAutomaton for ArrayList_ListIterator ~> java.util.ArrayList_ListItr - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.ArrayList_ListItr.class) -public final class ArrayList_ListItr implements LibSLRuntime.Automaton, ListIterator { - static { - Engine.assume(true); - } - - public ArrayList parent; - - public int cursor; - - public int expectedModCount; - - public int lastRet; - - @LibSLRuntime.AutomatonConstructor - public ArrayList_ListItr(Void __$lsl_token, final byte p0, final ArrayList p1, final int p2, - final int p3, final int p4) { - this.parent = p1; - this.cursor = p2; - this.expectedModCount = p3; - this.lastRet = p4; - } - - @LibSLRuntime.AutomatonConstructor - public ArrayList_ListItr(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, 0, 0, -1); - } - - /** - * [SUBROUTINE] ArrayList_ListIteratorAutomaton::_checkForComodification() -> void - * Source: java/util/ArrayList.ListIterator.lsl:55 - */ - private void _checkForComodification() { - /* body */ { - final int modCount = ((ArrayList) ((Object) this.parent)).modCount; - if (modCount != this.expectedModCount) { - throw new ConcurrentModificationException(); - } - } - } - - /** - * [FUNCTION] ArrayList_ListIteratorAutomaton::hasPrevious(ArrayList_ListIterator) -> boolean - * Source: java/util/ArrayList.ListIterator.lsl:65 - */ - public boolean hasPrevious() { - boolean result = false; - /* body */ { - result = this.cursor != 0; - } - return result; - } - - /** - * [FUNCTION] ArrayList_ListIteratorAutomaton::nextIndex(ArrayList_ListIterator) -> int - * Source: java/util/ArrayList.ListIterator.lsl:71 - */ - public int nextIndex() { - int result = 0; - /* body */ { - result = this.cursor; - } - return result; - } - - /** - * [FUNCTION] ArrayList_ListIteratorAutomaton::previousIndex(ArrayList_ListIterator) -> int - * Source: java/util/ArrayList.ListIterator.lsl:77 - */ - public int previousIndex() { - int result = 0; - /* body */ { - result = this.cursor - 1; - } - return result; - } - - /** - * [FUNCTION] ArrayList_ListIteratorAutomaton::hasNext(ArrayList_ListIterator) -> boolean - * Source: java/util/ArrayList.ListIterator.lsl:83 - */ - public boolean hasNext() { - boolean result = false; - /* body */ { - Engine.assume(this.parent != null); - result = this.cursor != ((ArrayList) ((Object) this.parent)).storage.size(); - } - return result; - } - - /** - * [FUNCTION] ArrayList_ListIteratorAutomaton::next(ArrayList_ListIterator) -> Object - * Source: java/util/ArrayList.ListIterator.lsl:92 - */ - public Object next() { - Object result = null; - /* body */ { - Engine.assume(this.parent != null); - _checkForComodification(); - final SymbolicList parentStorage = ((ArrayList) ((Object) this.parent)).storage; - final int i = this.cursor; - if (i >= parentStorage.size()) { - throw new NoSuchElementException(); - } - this.cursor = i + 1; - this.lastRet = i; - result = parentStorage.get(i); - } - return result; - } - - /** - * [FUNCTION] ArrayList_ListIteratorAutomaton::previous(ArrayList_ListIterator) -> Object - * Source: java/util/ArrayList.ListIterator.lsl:112 - */ - public Object previous() { - Object result = null; - /* body */ { - Engine.assume(this.parent != null); - _checkForComodification(); - final SymbolicList parentStorage = ((ArrayList) ((Object) this.parent)).storage; - final int i = this.cursor - 1; - if (i < 0) { - throw new NoSuchElementException(); - } - if (i >= parentStorage.size()) { - throw new ConcurrentModificationException(); - } - this.cursor = i; - this.lastRet = i; - result = parentStorage.get(i); - } - return result; - } - - /** - * [FUNCTION] ArrayList_ListIteratorAutomaton::remove(ArrayList_ListIterator) -> void - * Source: java/util/ArrayList.ListIterator.lsl:136 - */ - public void remove() { - /* body */ { - Engine.assume(this.parent != null); - if (this.lastRet < 0) { - throw new IllegalStateException(); - } - _checkForComodification(); - final SymbolicList pStorage = ((ArrayList) ((Object) this.parent)).storage; - if (this.lastRet >= pStorage.size()) { - throw new ConcurrentModificationException(); - } else { - ((ArrayList) ((Object) this.parent)).modCount += 1; - pStorage.remove(this.lastRet); - } - this.cursor = this.lastRet; - this.lastRet = -1; - this.expectedModCount = ((ArrayList) ((Object) this.parent)).modCount; - } - } - - /** - * [FUNCTION] ArrayList_ListIteratorAutomaton::set(ArrayList_ListIterator, Object) -> void - * Source: java/util/ArrayList.ListIterator.lsl:164 - */ - public void set(Object e) { - /* body */ { - Engine.assume(this.parent != null); - if (this.lastRet < 0) { - throw new IllegalStateException(); - } - _checkForComodification(); - final SymbolicList pStorage = ((ArrayList) ((Object) this.parent)).storage; - if (this.lastRet >= pStorage.size()) { - throw new ConcurrentModificationException(); - } else { - pStorage.set(this.lastRet, e); - } - } - } - - /** - * [FUNCTION] ArrayList_ListIteratorAutomaton::add(ArrayList_ListIterator, Object) -> void - * Source: java/util/ArrayList.ListIterator.lsl:182 - */ - public void add(Object e) { - /* body */ { - Engine.assume(this.parent != null); - _checkForComodification(); - final int i = this.cursor; - final SymbolicList pStorage = ((ArrayList) ((Object) this.parent)).storage; - if (this.lastRet > pStorage.size()) { - throw new ConcurrentModificationException(); - } else { - ((ArrayList) ((Object) this.parent)).modCount += 1; - pStorage.insert(i, e); - } - this.cursor = i + 1; - this.lastRet = -1; - this.expectedModCount = ((ArrayList) ((Object) this.parent)).modCount; - } - } - - /** - * [FUNCTION] ArrayList_ListIteratorAutomaton::forEachRemaining(ArrayList_ListIterator, Consumer) -> void - * Source: java/util/ArrayList.ListIterator.lsl:209 - */ - public void forEachRemaining(Consumer userAction) { - /* body */ { - Engine.assume(this.parent != null); - if (userAction == null) { - throw new NullPointerException(); - } - int i = this.cursor; - final SymbolicList es = ((ArrayList) ((Object) this.parent)).storage; - final int size = es.size(); - if (i < size) { - while ((i < size) && (((ArrayList) ((Object) this.parent)).modCount == this.expectedModCount)) { - final Object item = es.get(i); - userAction.accept(item); - i += 1; - } - ; - this.cursor = i; - this.lastRet = i - 1; - _checkForComodification(); - } - } - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(ArrayList_ListItr.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/ArrayList_Spliterator.java b/approximations/src/main/java/generated/java/util/ArrayList_Spliterator.java deleted file mode 100644 index 31ada83c..00000000 --- a/approximations/src/main/java/generated/java/util/ArrayList_Spliterator.java +++ /dev/null @@ -1,231 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/ArrayList.lsl:45 -// - java/util/ArrayList.Spliterator.lsl:16 -// -package generated.java.util; - -import generated.runtime.LibSLGlobals; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ConcurrentModificationException; -import java.util.Spliterator; -import java.util.function.Consumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import org.usvm.api.SymbolicList; -import runtime.LibSLRuntime; - -/** - * ArrayList_SpliteratorAutomaton for ArrayList_Spliterator ~> java.util.ArrayList_Spliterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.ArrayList_Spliterator.class) -public final class ArrayList_Spliterator implements LibSLRuntime.Automaton, Spliterator { - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public ArrayList parent; - - public int index; - - public int fence; - - public int expectedModCount; - - @LibSLRuntime.AutomatonConstructor - public ArrayList_Spliterator(Void __$lsl_token, final byte p0, final ArrayList p1, final int p2, - final int p3, final int p4) { - this.__$lsl_state = p0; - this.parent = p1; - this.index = p2; - this.fence = p3; - this.expectedModCount = p4; - } - - @LibSLRuntime.AutomatonConstructor - public ArrayList_Spliterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, null, 0, -1, 0); - } - - /** - * [CONSTRUCTOR] ArrayList_SpliteratorAutomaton::(ArrayList_Spliterator, ArrayList, int, int, int) -> void - * Source: java/util/ArrayList.Spliterator.lsl:81 - */ - private ArrayList_Spliterator(ArrayList _this, int origin, int fence, int expectedModCount) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - LibSLRuntime.not_implemented(/* inaccessible constructor */); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] ArrayList_SpliteratorAutomaton::_getFence() -> int - * Source: java/util/ArrayList.Spliterator.lsl:65 - */ - private int _getFence() { - int result = 0; - /* body */ { - if (this.fence == -1) { - Engine.assume(this.parent != null); - this.expectedModCount = ((ArrayList) ((Object) this.parent)).modCount; - this.fence = ((ArrayList) ((Object) this.parent)).storage.size(); - } - result = this.fence; - } - return result; - } - - /** - * [FUNCTION] ArrayList_SpliteratorAutomaton::characteristics(ArrayList_Spliterator) -> int - * Source: java/util/ArrayList.Spliterator.lsl:95 - */ - public int characteristics() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = LibSLGlobals.SPLITERATOR_ORDERED | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED; - } - return result; - } - - /** - * [FUNCTION] ArrayList_SpliteratorAutomaton::estimateSize(ArrayList_Spliterator) -> long - * Source: java/util/ArrayList.Spliterator.lsl:101 - */ - public long estimateSize() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _getFence() - this.index; - } - return result; - } - - /** - * [FUNCTION] ArrayList_SpliteratorAutomaton::forEachRemaining(ArrayList_Spliterator, Consumer) -> void - * Source: java/util/ArrayList.Spliterator.lsl:107 - */ - public void forEachRemaining(Consumer _action) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - Engine.assume(this.parent != null); - final SymbolicList a = ((ArrayList) ((Object) this.parent)).storage; - if (a == null) { - throw new ConcurrentModificationException(); - } - int hi = this.fence; - int mc = this.expectedModCount; - if (hi == -1) { - hi = a.size(); - mc = ((ArrayList) ((Object) this.parent)).modCount; - } - int i = this.index; - this.index = hi; - if ((i < 0) || (hi > a.size())) { - throw new ConcurrentModificationException(); - } - for (i = i; i < hi; i += 1) { - final Object item = a.get(i); - _action.accept(item); - } - ; - if (mc != ((ArrayList) ((Object) this.parent)).modCount) { - throw new ConcurrentModificationException(); - } - } - } - - /** - * [FUNCTION] ArrayList_SpliteratorAutomaton::getExactSizeIfKnown(ArrayList_Spliterator) -> long - * Source: java/util/ArrayList.Spliterator.lsl:154 - */ - public long getExactSizeIfKnown() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _getFence() - this.index; - } - return result; - } - - /** - * [FUNCTION] ArrayList_SpliteratorAutomaton::tryAdvance(ArrayList_Spliterator, Consumer) -> boolean - * Source: java/util/ArrayList.Spliterator.lsl:167 - */ - public boolean tryAdvance(Consumer _action) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - final int hi = _getFence(); - final int i = this.index; - if (i < hi) { - Engine.assume(this.parent != null); - this.index = i + 1; - final SymbolicList parentStorage = ((ArrayList) ((Object) this.parent)).storage; - final Object item = parentStorage.get(i); - _action.accept(item); - if (((ArrayList) ((Object) this.parent)).modCount != this.expectedModCount) { - throw new ConcurrentModificationException(); - } - result = true; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] ArrayList_SpliteratorAutomaton::trySplit(ArrayList_Spliterator) -> Spliterator - * Source: java/util/ArrayList.Spliterator.lsl:197 - */ - public Spliterator trySplit() { - Spliterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int hi = _getFence(); - final int lo = this.index; - final int mid = (lo + hi) >>> 1; - if (lo >= mid) { - result = null; - } else { - result = (stub.java.util.ArrayList_Spliterator) ((Object) new ArrayList_Spliterator((Void) null, - /* state = */ ArrayList_Spliterator.__$lsl_States.Initialized, - /* parent = */ this.parent, - /* index = */ lo, - /* fence = */ mid, - /* expectedModCount = */ this.expectedModCount - )); - } - this.index = mid; - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(ArrayList_Spliterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/ArrayList_SubList$ListIterator.java b/approximations/src/main/java/generated/java/util/ArrayList_SubList$ListIterator.java deleted file mode 100644 index 315f37c4..00000000 --- a/approximations/src/main/java/generated/java/util/ArrayList_SubList$ListIterator.java +++ /dev/null @@ -1,277 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/ArrayList.lsl:75 -// - java/util/ArrayList.SubList.ListIterator.lsl:16 -// -package generated.java.util; - -import java.lang.IllegalStateException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ConcurrentModificationException; -import java.util.ListIterator; -import java.util.NoSuchElementException; -import java.util.function.Consumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import org.usvm.api.SymbolicList; -import runtime.LibSLRuntime; - -/** - * ArrayList_SubList_ListIteratorAutomaton for ArrayList_SubList_ListIterator ~> java.util.ArrayList_SubList$ListIterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.ArrayList_SubList$ListIterator.class) -public final class ArrayList_SubList$ListIterator implements LibSLRuntime.Automaton, ListIterator { - static { - Engine.assume(true); - } - - public ArrayList root; - - public ArrayList_SubList sublist; - - public int cursor; - - public int expectedModCount; - - public int offset; - - public int size; - - public int lastRet; - - @LibSLRuntime.AutomatonConstructor - public ArrayList_SubList$ListIterator(Void __$lsl_token, final byte p0, final ArrayList p1, - final ArrayList_SubList p2, final int p3, final int p4, final int p5, final int p6, - final int p7) { - this.root = p1; - this.sublist = p2; - this.cursor = p3; - this.expectedModCount = p4; - this.offset = p5; - this.size = p6; - this.lastRet = p7; - } - - @LibSLRuntime.AutomatonConstructor - public ArrayList_SubList$ListIterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, null, 0, 0, 0, 0, -1); - } - - /** - * [SUBROUTINE] ArrayList_SubList_ListIteratorAutomaton::_checkForComodification() -> void - * Source: java/util/ArrayList.SubList.ListIterator.lsl:58 - */ - private void _checkForComodification() { - /* body */ { - final int modCount = ((ArrayList) ((Object) this.root)).modCount; - if (modCount != this.expectedModCount) { - throw new ConcurrentModificationException(); - } - } - } - - /** - * [FUNCTION] ArrayList_SubList_ListIteratorAutomaton::hasPrevious(ArrayList_SubList_ListIterator) -> boolean - * Source: java/util/ArrayList.SubList.ListIterator.lsl:68 - */ - public boolean hasPrevious() { - boolean result = false; - /* body */ { - result = this.cursor != 0; - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubList_ListIteratorAutomaton::nextIndex(ArrayList_SubList_ListIterator) -> int - * Source: java/util/ArrayList.SubList.ListIterator.lsl:74 - */ - public int nextIndex() { - int result = 0; - /* body */ { - result = this.cursor; - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubList_ListIteratorAutomaton::previousIndex(ArrayList_SubList_ListIterator) -> int - * Source: java/util/ArrayList.SubList.ListIterator.lsl:80 - */ - public int previousIndex() { - int result = 0; - /* body */ { - result = this.cursor - 1; - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubList_ListIteratorAutomaton::hasNext(ArrayList_SubList_ListIterator) -> boolean - * Source: java/util/ArrayList.SubList.ListIterator.lsl:86 - */ - public boolean hasNext() { - boolean result = false; - /* body */ { - result = this.cursor != this.size; - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubList_ListIteratorAutomaton::next(ArrayList_SubList_ListIterator) -> Object - * Source: java/util/ArrayList.SubList.ListIterator.lsl:92 - */ - public Object next() { - Object result = null; - /* body */ { - Engine.assume(this.root != null); - _checkForComodification(); - final SymbolicList rootStorage = ((ArrayList) ((Object) this.root)).storage; - final int i = this.offset + this.cursor; - if (i >= rootStorage.size()) { - throw new NoSuchElementException(); - } - this.lastRet = this.cursor; - this.cursor += 1; - result = rootStorage.get(i); - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubList_ListIteratorAutomaton::previous(ArrayList_SubList_ListIterator) -> Object - * Source: java/util/ArrayList.SubList.ListIterator.lsl:112 - */ - public Object previous() { - Object result = null; - /* body */ { - Engine.assume(this.root != null); - _checkForComodification(); - final int i = (this.offset + this.cursor) - 1; - if (i < this.offset) { - throw new NoSuchElementException(); - } - final SymbolicList rootStorage = ((ArrayList) ((Object) this.root)).storage; - if (i >= rootStorage.size()) { - throw new ConcurrentModificationException(); - } - this.cursor -= 1; - this.lastRet = this.cursor; - result = rootStorage.get(i); - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubList_ListIteratorAutomaton::remove(ArrayList_SubList_ListIterator) -> void - * Source: java/util/ArrayList.SubList.ListIterator.lsl:135 - */ - public void remove() { - /* body */ { - Engine.assume(this.root != null); - if (this.lastRet < 0) { - throw new IllegalStateException(); - } - _checkForComodification(); - if (this.lastRet >= this.size) { - throw new ConcurrentModificationException(); - } else { - ((ArrayList) ((Object) this.root))._deleteElement(this.offset + this.lastRet); - ((ArrayList_SubList) ((Object) this.sublist))._updateSizeAndModCount(-1); - this.expectedModCount = ((ArrayList) ((Object) this.root)).modCount; - this.size -= 1; - } - this.cursor = this.lastRet; - this.lastRet = -1; - } - } - - /** - * [FUNCTION] ArrayList_SubList_ListIteratorAutomaton::set(ArrayList_SubList_ListIterator, Object) -> void - * Source: java/util/ArrayList.SubList.ListIterator.lsl:163 - */ - public void set(Object e) { - /* body */ { - Engine.assume(this.root != null); - if (this.lastRet < 0) { - throw new IllegalStateException(); - } - _checkForComodification(); - final SymbolicList rootStorage = ((ArrayList) ((Object) this.root)).storage; - final int index = this.offset + this.lastRet; - if (index >= rootStorage.size()) { - throw new ConcurrentModificationException(); - } else { - rootStorage.set(index, e); - } - } - } - - /** - * [FUNCTION] ArrayList_SubList_ListIteratorAutomaton::add(ArrayList_SubList_ListIterator, Object) -> void - * Source: java/util/ArrayList.SubList.ListIterator.lsl:183 - */ - public void add(Object e) { - /* body */ { - Engine.assume(this.root != null); - _checkForComodification(); - final int i = this.offset + this.cursor; - if ((this.offset + this.lastRet) > ((ArrayList) ((Object) this.root)).storage.size()) { - throw new ConcurrentModificationException(); - } else { - ((ArrayList) ((Object) this.root))._addElement(i, e); - ((ArrayList_SubList) ((Object) this.sublist))._updateSizeAndModCount(1); - this.expectedModCount = ((ArrayList) ((Object) this.root)).modCount; - this.size += 1; - } - this.cursor += 1; - this.lastRet = -1; - } - } - - /** - * [FUNCTION] ArrayList_SubList_ListIteratorAutomaton::forEachRemaining(ArrayList_SubList_ListIterator, Consumer) -> void - * Source: java/util/ArrayList.SubList.ListIterator.lsl:210 - */ - public void forEachRemaining(Consumer userAction) { - /* body */ { - Engine.assume(this.root != null); - if (userAction == null) { - throw new NullPointerException(); - } - int i = this.cursor; - if (i < this.size) { - i += this.offset; - final SymbolicList es = ((ArrayList) ((Object) this.root)).storage; - if (i >= es.size()) { - throw new ConcurrentModificationException(); - } - final int end = this.offset + this.size; - for (i = i; i < end; i += 1) { - final Object item = es.get(i); - userAction.accept(item); - } - ; - this.cursor = i - this.offset; - this.lastRet = this.cursor - 1; - _checkForComodification(); - } - } - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(ArrayList_SubList$ListIterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/ArrayList_SubList$Spliterator.java b/approximations/src/main/java/generated/java/util/ArrayList_SubList$Spliterator.java deleted file mode 100644 index 8ea78534..00000000 --- a/approximations/src/main/java/generated/java/util/ArrayList_SubList$Spliterator.java +++ /dev/null @@ -1,212 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/ArrayList.lsl:65 -// - java/util/ArrayList.SubList.Spliterator.lsl:16 -// -package generated.java.util; - -import generated.runtime.LibSLGlobals; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ConcurrentModificationException; -import java.util.Spliterator; -import java.util.function.Consumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import org.usvm.api.SymbolicList; -import runtime.LibSLRuntime; - -/** - * ArrayList_SubList_SpliteratorAutomaton for ArrayList_SubList_Spliterator ~> java.util.ArrayList_SubList$Spliterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.ArrayList_SubList$Spliterator.class) -public final class ArrayList_SubList$Spliterator implements LibSLRuntime.Automaton, Spliterator { - static { - Engine.assume(true); - } - - public ArrayList root; - - public ArrayList_SubList parent; - - public int index; - - public int fence; - - public int expectedModCount; - - @LibSLRuntime.AutomatonConstructor - public ArrayList_SubList$Spliterator(Void __$lsl_token, final byte p0, final ArrayList p1, - final ArrayList_SubList p2, final int p3, final int p4, final int p5) { - this.root = p1; - this.parent = p2; - this.index = p3; - this.fence = p4; - this.expectedModCount = p5; - } - - @LibSLRuntime.AutomatonConstructor - public ArrayList_SubList$Spliterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, null, 0, -1, 0); - } - - /** - * [SUBROUTINE] ArrayList_SubList_SpliteratorAutomaton::_getFence() -> int - * Source: java/util/ArrayList.SubList.Spliterator.lsl:60 - */ - private int _getFence() { - int result = 0; - /* body */ { - if (this.fence == -1) { - Engine.assume(this.parent != null); - this.expectedModCount = ((ArrayList_SubList) ((Object) this.parent)).modCount; - this.fence = ((ArrayList_SubList) ((Object) this.parent)).length; - } - result = this.fence; - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubList_SpliteratorAutomaton::characteristics(ArrayList_SubList_Spliterator) -> int - * Source: java/util/ArrayList.SubList.Spliterator.lsl:80 - */ - public int characteristics() { - int result = 0; - /* body */ { - result = LibSLGlobals.SPLITERATOR_ORDERED | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED; - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubList_SpliteratorAutomaton::estimateSize(ArrayList_SubList_Spliterator) -> long - * Source: java/util/ArrayList.SubList.Spliterator.lsl:86 - */ - public long estimateSize() { - long result = 0L; - /* body */ { - result = _getFence() - this.index; - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubList_SpliteratorAutomaton::forEachRemaining(ArrayList_SubList_Spliterator, Consumer) -> void - * Source: java/util/ArrayList.SubList.Spliterator.lsl:92 - */ - public void forEachRemaining(Consumer _action) { - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - Engine.assume(this.root != null); - Engine.assume(this.parent != null); - final SymbolicList a = ((ArrayList) ((Object) this.root)).storage; - if (a == null) { - throw new ConcurrentModificationException(); - } - int hi = this.fence; - int mc = this.expectedModCount; - if (hi == -1) { - hi = ((ArrayList_SubList) ((Object) this.parent)).length; - mc = ((ArrayList_SubList) ((Object) this.parent)).modCount; - } - int i = this.index; - this.index = hi; - if ((i < 0) || (hi > ((ArrayList_SubList) ((Object) this.parent)).length)) { - throw new ConcurrentModificationException(); - } - for (i = i; i < hi; i += 1) { - final Object item = a.get(i); - _action.accept(item); - } - ; - if (mc != ((ArrayList_SubList) ((Object) this.parent)).modCount) { - throw new ConcurrentModificationException(); - } - } - } - - /** - * [FUNCTION] ArrayList_SubList_SpliteratorAutomaton::getExactSizeIfKnown(ArrayList_SubList_Spliterator) -> long - * Source: java/util/ArrayList.SubList.Spliterator.lsl:141 - */ - public long getExactSizeIfKnown() { - long result = 0L; - /* body */ { - result = _getFence() - this.index; - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubList_SpliteratorAutomaton::tryAdvance(ArrayList_SubList_Spliterator, Consumer) -> boolean - * Source: java/util/ArrayList.SubList.Spliterator.lsl:154 - */ - public boolean tryAdvance(Consumer _action) { - boolean result = false; - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - final int hi = _getFence(); - final int i = this.index; - if (i < hi) { - Engine.assume(this.root != null); - this.index = i + 1; - final SymbolicList rootStorage = ((ArrayList) ((Object) this.root)).storage; - final Object item = rootStorage.get(i); - _action.accept(item); - if (((ArrayList) ((Object) this.root)).modCount != this.expectedModCount) { - throw new ConcurrentModificationException(); - } - result = true; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubList_SpliteratorAutomaton::trySplit(ArrayList_SubList_Spliterator) -> Spliterator - * Source: java/util/ArrayList.SubList.Spliterator.lsl:184 - */ - public Spliterator trySplit() { - Spliterator result = null; - /* body */ { - final int hi = _getFence(); - final int lo = this.index; - final int mid = (lo + hi) >>> 1; - if (lo >= mid) { - result = null; - } else { - result = (stub.java.util.ArrayList_SubList$Spliterator) ((Object) new ArrayList_SubList$Spliterator((Void) null, - /* state = */ ArrayList_SubList$Spliterator.__$lsl_States.Initialized, - /* root = */ this.root, - /* parent = */ this.parent, - /* index = */ lo, - /* fence = */ mid, - /* expectedModCount = */ this.expectedModCount - )); - } - this.index = mid; - } - return result; - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(ArrayList_SubList$Spliterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/ArrayList_SubList.java b/approximations/src/main/java/generated/java/util/ArrayList_SubList.java deleted file mode 100644 index fdeadbf2..00000000 --- a/approximations/src/main/java/generated/java/util/ArrayList_SubList.java +++ /dev/null @@ -1,908 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/ArrayList.lsl:54 -// - java/util/ArrayList.SubList.lsl:16 -// -package generated.java.util; - -import java.lang.Object; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Collection; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.RandomAccess; -import java.util.Spliterator; -import java.util.function.Consumer; -import java.util.function.IntFunction; -import java.util.function.Predicate; -import java.util.function.UnaryOperator; -import java.util.stream.Stream; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import org.usvm.api.SymbolicList; -import runtime.LibSLRuntime; -import stub.java.util.stream.StreamLSL; - -/** - * ArrayList_SubListAutomaton for ArrayList_SubList ~> java.util.ArrayList_SubList - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.ArrayList_SubList.class) -public final class ArrayList_SubList implements LibSLRuntime.Automaton, List, RandomAccess { - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public ArrayList root; - - public ArrayList_SubList parentList; - - public int offset; - - public int length; - - public int modCount; - - @LibSLRuntime.AutomatonConstructor - public ArrayList_SubList(Void __$lsl_token, final byte p0, final ArrayList p1, - final ArrayList_SubList p2, final int p3, final int p4, final int p5) { - this.__$lsl_state = p0; - this.root = p1; - this.parentList = p2; - this.offset = p3; - this.length = p4; - this.modCount = p5; - } - - @LibSLRuntime.AutomatonConstructor - public ArrayList_SubList(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, null, null, 0, 0, 0); - } - - /** - * [CONSTRUCTOR] ArrayList_SubListAutomaton::(ArrayList_SubList, ArrayList, int, int) -> void - * Source: java/util/ArrayList.SubList.lsl:211 - */ - public ArrayList_SubList(ArrayList root, int fromIndex, int toIndex) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - LibSLRuntime.not_implemented(/* inaccessible constructor */); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] ArrayList_SubListAutomaton::(ArrayList_SubList, ArrayList_SubList, int, int) -> void - * Source: java/util/ArrayList.SubList.lsl:218 - */ - private ArrayList_SubList(ArrayList_SubList parent, int fromIndex, int toIndex) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - LibSLRuntime.not_implemented(/* inaccessible constructor */); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] ArrayList_SubListAutomaton::_addAllElements(int, Collection) -> boolean - * Source: java/util/ArrayList.SubList.lsl:91 - */ - private boolean _addAllElements(int index, Collection c) { - boolean result = false; - /* body */ { - Engine.assume(this.root != null); - final int effectiveIndex = this.offset + index; - ((ArrayList) ((Object) this.root))._rangeCheckForAdd(effectiveIndex); - final int collectionSize = c.size(); - if (collectionSize == 0) { - result = false; - } else { - result = true; - ((ArrayList) ((Object) this.root))._checkForComodification(this.modCount); - ((ArrayList) ((Object) this.root))._addAllElements(effectiveIndex, c); - _updateSizeAndModCount(collectionSize); - } - } - return result; - } - - /** - * [SUBROUTINE] ArrayList_SubListAutomaton::_updateSizeAndModCount(int) -> void - * Source: java/util/ArrayList.SubList.lsl:114 - */ - public void _updateSizeAndModCount(int sizeChange) { - /* body */ { - Engine.assume(this.root != null); - this.length += sizeChange; - this.modCount = ((ArrayList) ((Object) this.root)).modCount; - ArrayList_SubList aList = this.parentList; - while (aList != null) { - ((ArrayList_SubList) ((Object) aList)).length += sizeChange; - ((ArrayList_SubList) ((Object) aList)).modCount = this.modCount; - aList = ((ArrayList_SubList) ((Object) aList)).parentList; - } - ; - } - } - - /** - * [SUBROUTINE] ArrayList_SubListAutomaton::_indexOfElement(Object) -> int - * Source: java/util/ArrayList.SubList.lsl:139 - */ - private int _indexOfElement(Object o) { - int result = 0; - /* body */ { - Engine.assume(this.root != null); - ((ArrayList) ((Object) this.root))._checkForComodification(this.modCount); - final SymbolicList parentStorage = ((ArrayList) ((Object) this.root)).storage; - final int index = LibSLRuntime.ListActions.find(parentStorage, o, this.offset, this.offset + this.length); - if (index != -1) { - result = index - this.offset; - } else { - result = -1; - } - } - return result; - } - - /** - * [SUBROUTINE] ArrayList_SubListAutomaton::_makeStream(boolean) -> Stream - * Source: java/util/ArrayList.SubList.lsl:154 - */ - private Stream _makeStream(boolean parallel) { - Stream result = null; - /* body */ { - Engine.assume(this.root != null); - ((ArrayList) ((Object) this.root))._checkForComodification(this.modCount); - final SymbolicList parentStorage = ((ArrayList) ((Object) this.root)).storage; - final int count = this.length; - final Object[] items = new Object[count]; - int i = 0; - for (i = 0; i < count; i += 1) { - items[i] = parentStorage.get(this.offset + i); - } - ; - result = (StreamLSL) ((Object) new generated.java.util.stream.StreamLSL((Void) null, - /* state = */ generated.java.util.stream.StreamLSL.__$lsl_States.Initialized, - /* storage = */ items, - /* length = */ count, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ parallel, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [SUBROUTINE] ArrayList_SubListAutomaton::_batchRemove(Collection, boolean) -> boolean - * Source: java/util/ArrayList.SubList.lsl:186 - */ - private boolean _batchRemove(Collection c, boolean complement) { - boolean result = false; - /* body */ { - Engine.assume(this.root != null); - ((ArrayList) ((Object) this.root))._checkForComodification(this.modCount); - if (this.length != 0) { - final int oldRootLength = ((ArrayList) ((Object) this.root)).storage.size(); - result = ((ArrayList) ((Object) this.root))._batchRemove(c, complement, this.offset, this.offset + this.length); - if (result) { - final int newRootLength = ((ArrayList) ((Object) this.root)).storage.size(); - _updateSizeAndModCount(newRootLength - oldRootLength); - } - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::add(ArrayList_SubList, Object) -> boolean - * Source: java/util/ArrayList.SubList.lsl:230 - */ - public boolean add(Object e) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((ArrayList) ((Object) this.root))._checkForComodification(this.modCount); - final int effectiveIndex = this.offset + this.length; - ((ArrayList) ((Object) this.root))._addElement(effectiveIndex, e); - _updateSizeAndModCount(1); - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::add(ArrayList_SubList, int, Object) -> void - * Source: java/util/ArrayList.SubList.lsl:243 - */ - public void add(int index, Object element) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((ArrayList) ((Object) this.root))._checkForComodification(this.modCount); - final int effectiveIndex = this.offset + index; - ((ArrayList) ((Object) this.root))._addElement(effectiveIndex, element); - _updateSizeAndModCount(1); - } - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::addAll(ArrayList_SubList, Collection) -> boolean - * Source: java/util/ArrayList.SubList.lsl:256 - */ - public boolean addAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _addAllElements(this.length, c); - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::addAll(ArrayList_SubList, int, Collection) -> boolean - * Source: java/util/ArrayList.SubList.lsl:262 - */ - public boolean addAll(int index, Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _addAllElements(index, c); - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::clear(ArrayList_SubList) -> void - * Source: java/util/ArrayList.SubList.lsl:269 - */ - public void clear() { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((ArrayList) ((Object) this.root))._checkForComodification(this.modCount); - final int size = this.length; - if (size != 0) { - Engine.assume(size > 0); - final int end = this.offset - 1; - final int start = end + size; - final SymbolicList rootStorage = ((ArrayList) ((Object) this.root)).storage; - int i = 0; - for (i = start; i > end; i += -1) { - rootStorage.remove(i); - } - ; - ((ArrayList) ((Object) this.root)).modCount += 1; - _updateSizeAndModCount(-size); - } - } - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::contains(ArrayList_SubList, Object) -> boolean - * Source: java/util/ArrayList.SubList.lsl:301 - */ - public boolean contains(Object o) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _indexOfElement(o) != -1; - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::containsAll(ArrayList_SubList, Collection) -> boolean - * Source: java/util/ArrayList.SubList.lsl:308 - */ - public boolean containsAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = true; - if (!c.isEmpty()) { - Engine.assume(this.root != null); - final SymbolicList rootStorage = ((ArrayList) ((Object) this.root)).storage; - final int end = this.offset + this.length; - if ((c != null && c.getClass() == stub.java.util.ArrayList_SubList.class)) { - final ArrayList otherRoot = ((ArrayList_SubList) ((Object) c)).root; - Engine.assume(otherRoot != null); - final SymbolicList otherStorage = ((ArrayList) ((Object) otherRoot)).storage; - final int otherOffset = ((ArrayList_SubList) ((Object) c)).offset; - final int otherEnd = otherOffset + ((ArrayList_SubList) ((Object) c)).length; - Engine.assume(otherStorage != null); - Engine.assume(otherOffset >= 0); - Engine.assume(otherEnd >= 0); - int i = otherOffset; - while (result && (i < otherEnd)) { - final Object item = otherStorage.get(i); - result = LibSLRuntime.ListActions.find(rootStorage, item, this.offset, end) != -1; - i += 1; - } - ; - } else { - final Iterator iter = c.iterator(); - while (result && iter.hasNext()) { - final Object item = iter.next(); - result = LibSLRuntime.ListActions.find(rootStorage, item, this.offset, end) != -1; - } - ; - } - } - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::equals(ArrayList_SubList, Object) -> boolean - * Source: java/util/ArrayList.SubList.lsl:364 - */ - public boolean equals(Object o) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (o == this) { - result = true; - } else { - result = (o != null && o.getClass() == stub.java.util.ArrayList_SubList.class); - if (result) { - Engine.assume(this.root != null); - final int otherLength = ((ArrayList_SubList) ((Object) o)).length; - Engine.assume(otherLength >= 0); - result = this.length == otherLength; - if (result) { - result = ((ArrayList) ((Object) this.root))._equalsRange(((List) o), this.offset, this.offset + this.length); - ((ArrayList) ((Object) this.root))._checkForComodification(this.modCount); - } - } - } - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::forEach(ArrayList_SubList, Consumer) -> void - * Source: java/util/ArrayList.SubList.lsl:392 - */ - public void forEach(Consumer _action) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.length != 0) { - Engine.assume(this.length > 0); - Engine.assume(this.root != null); - final SymbolicList rootStorage = ((ArrayList) ((Object) this.root)).storage; - final int expectedModCount = ((ArrayList) ((Object) this.root)).modCount; - this.modCount = expectedModCount; - int i = this.offset; - final int end = this.offset + this.length; - while ((i < end) && (((ArrayList) ((Object) this.root)).modCount == expectedModCount)) { - final Object item = rootStorage.get(i); - _action.accept(item); - i += 1; - } - ; - ((ArrayList) ((Object) this.root))._checkForComodification(expectedModCount); - } - } - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::get(ArrayList_SubList, int) -> Object - * Source: java/util/ArrayList.SubList.lsl:424 - */ - public Object get(int index) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((ArrayList) ((Object) this.root))._checkValidIndex(index, this.length); - ((ArrayList) ((Object) this.root))._checkForComodification(this.modCount); - final int effectiveIndex = this.offset + index; - result = ((ArrayList) ((Object) this.root)).storage.get(effectiveIndex); - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::hashCode(ArrayList_SubList) -> int - * Source: java/util/ArrayList.SubList.lsl:436 - */ - public int hashCode() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = 1; - if (this.length != 0) { - Engine.assume(this.length > 0); - Engine.assume(this.root != null); - final SymbolicList rootStorage = ((ArrayList) ((Object) this.root)).storage; - int i = this.offset; - final int end = this.offset + this.length; - for (i = i; i < end; i += 1) { - final Object item = rootStorage.get(i); - result = (31 * result) + LibSLRuntime.hashCode(item); - } - ; - ((ArrayList) ((Object) this.root))._checkForComodification(this.modCount); - } - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::indexOf(ArrayList_SubList, Object) -> int - * Source: java/util/ArrayList.SubList.lsl:464 - */ - public int indexOf(Object o) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _indexOfElement(o); - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::isEmpty(ArrayList_SubList) -> boolean - * Source: java/util/ArrayList.SubList.lsl:471 - */ - public boolean isEmpty() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.length == 0; - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::iterator(ArrayList_SubList) -> Iterator - * Source: java/util/ArrayList.SubList.lsl:477 - */ - public Iterator iterator() { - Iterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (stub.java.util.ArrayList_SubList$ListIterator) ((Object) new ArrayList_SubList$ListIterator((Void) null, - /* state = */ ArrayList_SubList$ListIterator.__$lsl_States.Initialized, - /* root = */ this.root, - /* sublist = */ this, - /* cursor = */ 0, - /* expectedModCount = */ this.modCount, - /* offset = */ this.offset, - /* size = */ this.length, - /* lastRet = */ -1 - )); - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::lastIndexOf(ArrayList_SubList, Object) -> int - * Source: java/util/ArrayList.SubList.lsl:490 - */ - public int lastIndexOf(Object o) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((ArrayList) ((Object) this.root))._checkForComodification(this.modCount); - if (this.length == 0) { - result = -1; - } else { - Engine.assume(this.length > 0); - final int end = this.offset + this.length; - final SymbolicList rootStorage = ((ArrayList) ((Object) this.root)).storage; - result = LibSLRuntime.ListActions.find(rootStorage, o, this.offset, end); - if (result != -1) { - final int nextIndex = result + 1; - if (nextIndex < end) { - final int rightIndex = LibSLRuntime.ListActions.find(rootStorage, o, nextIndex, end); - Engine.assume(rightIndex == -1); - } - result -= this.offset; - } - } - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::listIterator(ArrayList_SubList) -> ListIterator - * Source: java/util/ArrayList.SubList.lsl:524 - */ - public ListIterator listIterator() { - ListIterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (stub.java.util.ArrayList_SubList$ListIterator) ((Object) new ArrayList_SubList$ListIterator((Void) null, - /* state = */ ArrayList_SubList$ListIterator.__$lsl_States.Initialized, - /* root = */ this.root, - /* sublist = */ this, - /* cursor = */ 0, - /* expectedModCount = */ this.modCount, - /* offset = */ this.offset, - /* size = */ this.length, - /* lastRet = */ -1 - )); - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::listIterator(ArrayList_SubList, int) -> ListIterator - * Source: java/util/ArrayList.SubList.lsl:537 - */ - public ListIterator listIterator(int index) { - ListIterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (stub.java.util.ArrayList_SubList$ListIterator) ((Object) new ArrayList_SubList$ListIterator((Void) null, - /* state = */ ArrayList_SubList$ListIterator.__$lsl_States.Initialized, - /* root = */ this.root, - /* sublist = */ this, - /* cursor = */ index, - /* expectedModCount = */ this.modCount, - /* offset = */ this.offset, - /* size = */ this.length, - /* lastRet = */ -1 - )); - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::parallelStream(ArrayList_SubList) -> Stream - * Source: java/util/ArrayList.SubList.lsl:551 - */ - public Stream parallelStream() { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _makeStream(true); - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::remove(ArrayList_SubList, Object) -> boolean - * Source: java/util/ArrayList.SubList.lsl:558 - */ - public boolean remove(Object o) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - final int end = this.offset + this.length; - final SymbolicList rootStorage = ((ArrayList) ((Object) this.root)).storage; - final int index = LibSLRuntime.ListActions.find(rootStorage, o, this.offset, end); - result = index != -1; - if (result) { - ((ArrayList) ((Object) this.root))._checkForComodification(this.modCount); - ((ArrayList) ((Object) this.root))._deleteElement(index); - _updateSizeAndModCount(-1); - } - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::remove(ArrayList_SubList, int) -> Object - * Source: java/util/ArrayList.SubList.lsl:578 - */ - public Object remove(int index) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((ArrayList) ((Object) this.root))._checkValidIndex(index, this.length); - ((ArrayList) ((Object) this.root))._checkForComodification(this.modCount); - final int effectiveIndex = this.offset + index; - result = ((ArrayList) ((Object) this.root))._deleteElement(effectiveIndex); - _updateSizeAndModCount(-1); - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::removeAll(ArrayList_SubList, Collection) -> boolean - * Source: java/util/ArrayList.SubList.lsl:592 - */ - public boolean removeAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _batchRemove(c, false); - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::removeIf(ArrayList_SubList, Predicate) -> boolean - * Source: java/util/ArrayList.SubList.lsl:598 - */ - public boolean removeIf(Predicate filter) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((ArrayList) ((Object) this.root))._checkForComodification(this.modCount); - final int size = this.length; - if (size != 0) { - final int oldRootLength = ((ArrayList) ((Object) this.root)).storage.size(); - result = ((ArrayList) ((Object) this.root))._removeIf(filter, this.offset, this.offset + this.length); - if (result) { - final int newRootLength = ((ArrayList) ((Object) this.root)).storage.size(); - _updateSizeAndModCount(newRootLength - oldRootLength); - } - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::replaceAll(ArrayList_SubList, UnaryOperator) -> void - * Source: java/util/ArrayList.SubList.lsl:622 - */ - public void replaceAll(UnaryOperator operator) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((ArrayList) ((Object) this.root))._replaceAllRange(operator, this.offset, this.offset + this.length); - } - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::retainAll(ArrayList_SubList, Collection) -> boolean - * Source: java/util/ArrayList.SubList.lsl:629 - */ - public boolean retainAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _batchRemove(c, true); - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::set(ArrayList_SubList, int, Object) -> Object - * Source: java/util/ArrayList.SubList.lsl:635 - */ - public Object set(int index, Object element) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((ArrayList) ((Object) this.root))._checkValidIndex(index, this.length); - ((ArrayList) ((Object) this.root))._checkForComodification(this.modCount); - final SymbolicList parentStorage = ((ArrayList) ((Object) this.root)).storage; - final int effectiveIndex = this.offset + index; - result = parentStorage.get(effectiveIndex); - parentStorage.set(effectiveIndex, element); - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::size(ArrayList_SubList) -> int - * Source: java/util/ArrayList.SubList.lsl:649 - */ - public int size() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((ArrayList) ((Object) this.root))._checkForComodification(this.modCount); - result = this.length; - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::sort(ArrayList_SubList, Comparator) -> void - * Source: java/util/ArrayList.SubList.lsl:659 - */ - public void sort(Comparator c) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((ArrayList) ((Object) this.root))._do_sort(this.offset, this.offset + this.length, c); - this.modCount = ((ArrayList) ((Object) this.root)).modCount; - } - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::spliterator(ArrayList_SubList) -> Spliterator - * Source: java/util/ArrayList.SubList.lsl:667 - */ - public Spliterator spliterator() { - Spliterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (stub.java.util.ArrayList_SubList$Spliterator) ((Object) new ArrayList_SubList$Spliterator((Void) null, - /* state = */ ArrayList_SubList$Spliterator.__$lsl_States.Initialized, - /* root = */ this.root, - /* parent = */ this, - /* index = */ 0, - /* fence = */ -1, - /* expectedModCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::stream(ArrayList_SubList) -> Stream - * Source: java/util/ArrayList.SubList.lsl:677 - */ - public Stream stream() { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _makeStream(false); - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::subList(ArrayList_SubList, int, int) -> List - * Source: java/util/ArrayList.SubList.lsl:683 - */ - public List subList(int fromIndex, int toIndex) { - List result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((ArrayList) ((Object) this.root))._subListRangeCheck(fromIndex, toIndex, this.length); - result = (stub.java.util.ArrayList_SubList) ((Object) new ArrayList_SubList((Void) null, - /* state = */ ArrayList_SubList.__$lsl_States.Initialized, - /* root = */ this.root, - /* parentList = */ this, - /* offset = */ this.offset + fromIndex, - /* length = */ toIndex - fromIndex, - /* modCount = */ this.modCount - )); - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::toArray(ArrayList_SubList) -> array - * Source: java/util/ArrayList.SubList.lsl:699 - */ - public Object[] toArray() { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((ArrayList) ((Object) this.root))._checkForComodification(this.modCount); - result = new Object[this.length]; - final SymbolicList rootStorage = ((ArrayList) ((Object) this.root)).storage; - final int end = this.offset + this.length; - int i = 0; - int j = 0; - for (i = this.offset; i < end; i += 1) { - result[j] = rootStorage.get(i); - j += 1; - } - ; - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::toArray(ArrayList_SubList, IntFunction) -> array - * Source: java/util/ArrayList.SubList.lsl:724 - */ - public Object[] toArray(IntFunction generator) { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final Object[] a = ((Object[]) generator.apply(0)); - final int aSize = a.length; - Engine.assume(this.root != null); - ((ArrayList) ((Object) this.root))._checkForComodification(this.modCount); - result = new Object[this.length]; - final SymbolicList rootStorage = ((ArrayList) ((Object) this.root)).storage; - final int end = this.offset + this.length; - int i = 0; - int j = 0; - for (i = this.offset; i < end; i += 1) { - result[j] = rootStorage.get(i); - j += 1; - } - ; - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::toArray(ArrayList_SubList, array) -> array - * Source: java/util/ArrayList.SubList.lsl:746 - */ - public Object[] toArray(Object[] a) { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((ArrayList) ((Object) this.root))._checkForComodification(this.modCount); - final int aSize = a.length; - if (aSize < this.length) { - a = new Object[this.length]; - } - result = a; - final SymbolicList rootStorage = ((ArrayList) ((Object) this.root)).storage; - final int end = this.offset + this.length; - int i = 0; - int j = 0; - for (i = this.offset; i < end; i += 1) { - result[j] = rootStorage.get(i); - j += 1; - } - ; - if (aSize > this.length) { - result[aSize] = null; - } - } - return result; - } - - /** - * [FUNCTION] ArrayList_SubListAutomaton::toString(ArrayList_SubList) -> String - * Source: java/util/ArrayList.SubList.lsl:773 - */ - public String toString() { - String result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.length == 0) { - result = "[]"; - } else { - result = "["; - Engine.assume(this.root != null); - final SymbolicList rootStorage = ((ArrayList) ((Object) this.root)).storage; - int i = this.offset; - final int end = this.offset + this.length; - int counter = this.length; - for (i = i; i < end; i += 1) { - final Object item = rootStorage.get(i); - result = result.concat(LibSLRuntime.toString(item)); - counter -= 1; - if (counter != 0) { - result = result.concat(", "); - } - } - ; - result = result.concat("]"); - } - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(ArrayList_SubList.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/BufferImpl.java b/approximations/src/main/java/generated/java/util/BufferImpl.java new file mode 100644 index 00000000..4d70e115 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/BufferImpl.java @@ -0,0 +1,283 @@ +package generated.java.util; + +import jdk.internal.access.SharedSecrets; +import jdk.internal.misc.ScopedMemoryAccess; +import jdk.internal.vm.annotation.ForceInline; +import jdk.internal.vm.annotation.IntrinsicCandidate; +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; + +import java.nio.*; + +@Approximate(java.nio.Buffer.class) +public abstract class BufferImpl { + private int mark = -1; + private int position = 0; + private int limit; + private int capacity; + protected int offset = 0; + + + BufferImpl(int cap) { + this.capacity = cap; + bufferAssume(); + } + + BufferImpl(int mark, int pos, int lim, int cap) { + if (cap < 0) + throw createCapacityException(cap); + this.capacity = cap; + limit(lim); + position(pos); + if (mark >= 0) { + if (mark > pos) + throw new IllegalArgumentException("mark > position: (" + + mark + " > " + pos + ")"); + this.mark = mark; + } + bufferAssume(); + } + + protected void bufferAssume() { + Engine.assume(0 <= position); + Engine.assume(position <= limit); + Engine.assume(limit <= capacity); + Engine.assume(mark <= position); + Engine.assume(mark >= -1); + } + + static IllegalArgumentException createSameBufferException() { + return new IllegalArgumentException("The source buffer is this buffer"); + } + + static IllegalArgumentException createCapacityException(int capacity) { + assert capacity < 0 : "capacity expected to be negative"; + return new IllegalArgumentException("capacity < 0: (" + + capacity + " < 0)"); + } + + protected int applyOffset(int i) { + Engine.assume(offset >= 0); + return i + offset; + } + + public final int capacity() { + bufferAssume(); + return capacity; + } + + public final int position() { + bufferAssume(); + return position; + } + + public BufferImpl position(int newPosition) { + if (newPosition > limit | newPosition < 0) + throw createPositionException(newPosition); + if (mark > newPosition) mark = -1; + position = newPosition; + bufferAssume(); + return this; + } + + private IllegalArgumentException createPositionException(int newPosition) { + String msg; + + if (newPosition > limit) { + msg = "newPosition > limit: (" + newPosition + " > " + limit + ")"; + } else { + assert newPosition < 0 : "newPosition expected to be negative"; + msg = "newPosition < 0: (" + newPosition + " < 0)"; + } + + return new IllegalArgumentException(msg); + } + + public final int limit() { + return limit; + } + + public BufferImpl limit(int newLimit) { + if (newLimit > capacity | newLimit < 0) + throw createLimitException(newLimit); + limit = newLimit; + if (position > newLimit) position = newLimit; + if (mark > newLimit) mark = -1; + bufferAssume(); + return this; + } + + private IllegalArgumentException createLimitException(int newLimit) { + String msg; + + if (newLimit > capacity) { + msg = "newLimit > capacity: (" + newLimit + " > " + capacity + ")"; + } else { + assert newLimit < 0 : "newLimit expected to be negative"; + msg = "newLimit < 0: (" + newLimit + " < 0)"; + } + + return new IllegalArgumentException(msg); + } + + public BufferImpl mark() { + bufferAssume(); + mark = position; + bufferAssume(); + return this; + } + + public BufferImpl reset() { + bufferAssume(); + int m = mark; + if (m < 0) + throw new InvalidMarkException(); + position = m; + bufferAssume(); + return this; + } + + public BufferImpl clear() { + bufferAssume(); + position = 0; + limit = capacity; + mark = -1; + bufferAssume(); + return this; + } + + public BufferImpl flip() { + bufferAssume(); + limit = position; + position = 0; + mark = -1; + bufferAssume(); + return this; + } + + public BufferImpl rewind() { + position = 0; + mark = -1; + bufferAssume(); + return this; + } + + public final int remaining() { + bufferAssume(); + int rem = limit - position; + return rem > 0 ? rem : 0; + } + + public final boolean hasRemaining() { + bufferAssume(); + return position < limit; + } + + public abstract boolean isReadOnly(); + + public abstract boolean hasArray(); + + public abstract Object array(); + + public abstract int arrayOffset(); + + public abstract boolean isDirect(); + + public abstract BufferImpl slice(); + + public abstract BufferImpl slice(int index, int length); + + public abstract BufferImpl duplicate(); + + abstract Object base(); + + final int nextGetIndex() { + bufferAssume(); + int p = position; + if (p >= limit) + throw new BufferUnderflowException(); + position = p + 1; + bufferAssume(); + return p; + } + + final int nextGetIndex(int nb) { + bufferAssume(); + int p = position; + if (limit - p < nb) + throw new BufferUnderflowException(); + position = p + nb; + bufferAssume(); + return p; + } + + final int nextPutIndex() { + bufferAssume(); + int p = position; + if (p >= limit) + throw new BufferOverflowException(); + position = p + 1; + bufferAssume(); + return p; + } + + final int nextPutIndex(int nb) { + bufferAssume(); + int p = position; + if (limit - p < nb) + throw new BufferOverflowException(); + position = p + nb; + bufferAssume(); + return p; + } + + @IntrinsicCandidate + final int checkIndex(int i) { + bufferAssume(); + if ((i < 0) || (i >= limit)) + throw new IndexOutOfBoundsException(); + return i; + } + + final int checkIndex(int i, int nb) { + bufferAssume(); + if ((i < 0) || (nb > limit - i)) + throw new IndexOutOfBoundsException(); + return i; + } + + final int markValue() { + bufferAssume(); + return mark; + } + + final void discardMark() { + bufferAssume(); + mark = -1; + } + + protected int checkFromIndexSize(int fromIndex, int size, int length) { + if ((length | fromIndex | size) < 0 || size > length - fromIndex) + throw new IndexOutOfBoundsException(); + return fromIndex; + } + + protected int checkFromToIndex(int fromIndex, int toIndex, int length) { + if (fromIndex < 0 || fromIndex > toIndex || toIndex > length) + throw new IndexOutOfBoundsException(); + return fromIndex; + } + + @ForceInline + final ScopedMemoryAccess.Scope scope() { + throw new UnsupportedOperationException(); + } + + final void checkScope() { + throw new UnsupportedOperationException(); + } + + static { + SharedSecrets.setJavaNioAccess(null); + } +} diff --git a/approximations/src/main/java/generated/java/util/ByteBufferImpl.java b/approximations/src/main/java/generated/java/util/ByteBufferImpl.java new file mode 100644 index 00000000..0841dd0d --- /dev/null +++ b/approximations/src/main/java/generated/java/util/ByteBufferImpl.java @@ -0,0 +1,576 @@ +package generated.java.util; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +import java.nio.*; + +@Approximate(java.nio.ByteBuffer.class) +public abstract class ByteBufferImpl extends BufferImpl implements Comparable { + byte[] storage; + boolean isReadOnly; + + ByteBufferImpl(int mark, int pos, int lim, int cap, + byte[] hb, int offset) + { + super(mark, pos, lim, cap); + this.storage = hb; + this.offset = offset; + } + + ByteBufferImpl(int mark, int pos, int lim, int cap, byte[] segment) { + this(mark, pos, lim, cap, segment, 0); + } + + ByteBufferImpl(byte[] hb, int cap) { + super(cap); + this.storage = hb; + this.offset = 0; + } + + @Override + Object base() { + return storage; + } + + public static ByteBufferImpl allocateDirect(int capacity) { + return new DirectByteBufferImpl(capacity); + } + + public static ByteBufferImpl allocate(int capacity) { + if (capacity < 0) + throw createCapacityException(capacity); + return new HeapByteBufferImpl(capacity, capacity); + } + + public static ByteBufferImpl wrap(byte[] array, + int offset, int length) + { + try { + return new HeapByteBufferImpl(array, offset, length); + } catch (IllegalArgumentException x) { + throw new IndexOutOfBoundsException(); + } + } + + public static ByteBufferImpl wrap(byte[] array) { + return wrap(array, 0, array.length); + } + + @Override + public abstract ByteBufferImpl slice(); + + @Override + public abstract ByteBufferImpl slice(int index, int length); + + @Override + public abstract ByteBufferImpl duplicate(); + + public abstract ByteBufferImpl asReadOnlyBuffer(); + + public byte get() { + int indexWithOffset = applyOffset(nextGetIndex()); + Engine.assume(indexWithOffset < storage.length); + return storage[indexWithOffset]; + } + + public ByteBufferImpl put(byte b) { + int indexWithOffset = applyOffset(nextPutIndex()); + Engine.assume(indexWithOffset < storage.length); + storage[indexWithOffset] = b; + return this; + } + + public byte get(int index) { + int indexWithOffset = applyOffset(checkIndex(index)); + Engine.assume(indexWithOffset < storage.length); + return storage[indexWithOffset]; + } + + public ByteBufferImpl put(int index, byte b) { + int indexWithOffset = applyOffset(checkIndex(index)); + Engine.assume(indexWithOffset < storage.length); + storage[indexWithOffset] = b; + return this; + } + + public ByteBufferImpl get(byte[] dst, int offset, int length) { + checkFromIndexSize(offset, length, dst.length); + if (length > remaining()) + throw new BufferUnderflowException(); + int indexWithOffset = applyOffset(nextGetIndex(length)); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(storage, indexWithOffset, dst, offset, length); + return this; + } + + public ByteBufferImpl get(byte[] dst) { + return get(dst, 0, dst.length); + } + + public ByteBufferImpl get(int index, byte[] dst, int offset, int length) { + checkFromIndexSize(index, length, limit()); + checkFromIndexSize(offset, length, dst.length); + int indexWithOffset = applyOffset(nextGetIndex(length)); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(storage, indexWithOffset, dst, offset, length); + return this; + } + + public ByteBufferImpl get(int index, byte[] dst) { + return get(index, dst, 0, dst.length); + } + + public ByteBufferImpl put(ByteBufferImpl src) { + if (src == this) + throw createSameBufferException(); + if (isReadOnly()) + throw new ReadOnlyBufferException(); + + int srcPos = src.position(); + int srcLim = src.limit(); + int srcRem = (srcPos <= srcLim ? srcLim - srcPos : 0); + int pos = position(); + int lim = limit(); + int rem = (pos <= lim ? lim - pos : 0); + + if (srcRem > rem) + throw new BufferOverflowException(); + + putBuffer(pos, src, srcPos, srcRem); + + position(pos + srcRem); + src.position(srcPos + srcRem); + + return this; + } + + public ByteBufferImpl put(int index, ByteBufferImpl src, int offset, int length) { + checkFromIndexSize(index, length, limit()); + checkFromIndexSize(offset, length, src.limit()); + if (isReadOnly()) + throw new ReadOnlyBufferException(); + + putBuffer(index, src, offset, length); + + return this; + } + + void putBuffer(int pos, ByteBufferImpl src, int srcPos, int n) { + Object srcBase = src.base(); + assert srcBase != null || src.isDirect(); + Object base = base(); + assert base != null || isDirect(); + int indexWithOffset = applyOffset(pos); + int srcIndexWithOffset = src.applyOffset(srcPos); + Engine.assume(indexWithOffset + n < storage.length); + Engine.assume(srcIndexWithOffset + n < src.storage.length); + LibSLRuntime.ArrayActions.copy(src.storage, srcIndexWithOffset, storage, indexWithOffset, n); + } + + public ByteBufferImpl put(byte[] src, int offset, int length) { + checkFromIndexSize(offset, length, src.length); + if (length > remaining()) + throw new BufferOverflowException(); + int indexWithOffset = applyOffset(nextPutIndex(length)); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(src, offset, storage, indexWithOffset, length); + return this; + } + + public final ByteBufferImpl put(byte[] src) { + return put(src, 0, src.length); + } + + public ByteBufferImpl put(int index, byte[] src, int offset, int length) { + if (isReadOnly()) + throw new ReadOnlyBufferException(); + checkFromIndexSize(index, length, limit()); + checkFromIndexSize(offset, length, src.length); + int indexWithOffset = applyOffset(index); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(src, offset, storage, indexWithOffset, length); + return this; + } + + public ByteBufferImpl put(int index, byte[] src) { + return put(index, src, 0, src.length); + } + + public final boolean hasArray() { + return (storage != null) && !isReadOnly; + } + + public final byte[] array() { + if (storage == null) + throw new UnsupportedOperationException(); + if (isReadOnly) + throw new ReadOnlyBufferException(); + return storage; + } + + public final int arrayOffset() { + if (storage == null) + throw new UnsupportedOperationException(); + if (isReadOnly) + throw new ReadOnlyBufferException(); + return offset; + } + + @Override + public ByteBufferImpl position(int newPosition) { + super.position(newPosition); + return this; + } + + @Override + public ByteBufferImpl limit(int newLimit) { + super.limit(newLimit); + return this; + } + + @Override + public ByteBufferImpl mark() { + super.mark(); + return this; + } + + @Override + public ByteBufferImpl reset() { + super.reset(); + return this; + } + + @Override + public ByteBufferImpl clear() { + super.clear(); + return this; + } + + @Override + public ByteBufferImpl flip() { + super.flip(); + return this; + } + + @Override + public ByteBufferImpl rewind() { + super.rewind(); + return this; + } + + public ByteBufferImpl compact() { + int pos = position(); + int lim = limit(); + assert (pos <= lim); + int rem = lim - pos; + int srcIndexWithOffset = applyOffset(pos); + int dstIndexWithOffset = applyOffset(0); + Engine.assume(srcIndexWithOffset + rem < storage.length); + Engine.assume(dstIndexWithOffset + rem < storage.length); + LibSLRuntime.ArrayActions.copy(storage, srcIndexWithOffset, storage, dstIndexWithOffset, rem); + position(rem); + limit(capacity()); + discardMark(); + return this; + } + + public abstract boolean isDirect(); + + public String toString() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public int hashCode() { + int h = 1; + int p = position(); + for (int i = limit() - 1; i >= p; i--) + h = 31 * h + (int)get(i); + return h; + } + + private int mismatch(ByteBufferImpl a, int aOff, ByteBufferImpl b, int bOff, int length) { + for (int i = 0; i < length; i++) { + if (a.get(aOff + i) != b.get(bOff + i)) + return i; + } + return -1; + } + + public boolean equals(Object ob) { + if (this == ob) + return true; + if (!(ob instanceof ByteBufferImpl)) + return false; + ByteBufferImpl that = (ByteBufferImpl)ob; + int thisPos = this.position(); + int thisRem = this.limit() - thisPos; + int thatPos = that.position(); + int thatRem = that.limit() - thatPos; + if (thisRem < 0 || thisRem != thatRem) + return false; + return mismatch(this, thisPos, that, thatPos, thisRem) < 0; + } + + public int compareTo(ByteBufferImpl that) { + int thisPos = this.position(); + int thisRem = this.limit() - thisPos; + int thatPos = that.position(); + int thatRem = that.limit() - thatPos; + int length = thisRem < thatRem ? thisRem : thatRem; + if (length < 0) + return -1; + int i = mismatch(this, thisPos, + that, thatPos, + length); + if (i >= 0) { + return compare(this.get(thisPos + i), that.get(thatPos + i)); + } + return thisRem - thatRem; + } + + private static int compare(byte x, byte y) { + return x - y; + } + + public int mismatch(ByteBufferImpl that) { + int thisPos = this.position(); + int thisRem = this.limit() - thisPos; + int thatPos = that.position(); + int thatRem = that.limit() - thatPos; + int length = thisRem < thatRem ? thisRem : thatRem; + if (length < 0) + return -1; + int r = mismatch(this, thisPos,that, thatPos, length); + return (r == -1 && thisRem != thatRem) ? length : r; + } + + boolean bigEndian = true; + boolean nativeByteOrder = true; + + public final ByteOrder order() { + return bigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN; + } + + public final ByteBufferImpl order(ByteOrder bo) { + if (bo != ByteOrder.BIG_ENDIAN) { + throw new UnsupportedOperationException(); + } + return this; + } + + public final int alignmentOffset(int index, int unitSize) { + throw new UnsupportedOperationException(); + } + + public final ByteBufferImpl alignedSlice(int unitSize) { + int pos = position(); + int lim = limit(); + + int pos_mod = alignmentOffset(pos, unitSize); + int lim_mod = alignmentOffset(lim, unitSize); + + int aligned_pos = (pos_mod > 0) + ? pos + (unitSize - pos_mod) + : pos; + + int aligned_lim = lim - lim_mod; + + if (aligned_pos > lim || aligned_lim < pos) { + aligned_pos = aligned_lim = pos; + } + + return slice(aligned_pos, aligned_lim - aligned_pos); + } + + protected char scopedGetChar(int i, boolean be) { + return (char)scopedGetShort(i, be); + } + + protected ByteBufferImpl scopedPutChar(int i, char x, boolean be) { + return scopedPutShort(i, (short)x, be); + } + + protected short scopedGetShort(int i, boolean be) { + checkIndex(i, 2); + int part1 = (get(i) & 0xff); + int part2 = (get(i + 1) & 0xff); + return (short)((part1 << 8) | part2); + } + + protected ByteBufferImpl scopedPutShort(int i, short x, boolean be) { + checkIndex(i, 2); + put(i, (byte)x); + put(i + 1, (byte)(x >>> 8)); + return this; + } + + protected int scopedGetInt(int i, boolean be) { + checkIndex(i, 4); + int part1 = (get(i) & 0xff); + int part2 = (get(i + 1) & 0xff); + int part3 = (get(i + 2) & 0xff); + int part4 = (get(i + 3) & 0xff); + return ((part1 << 24) | (part2 << 16) | (part3 << 8) | part4); + } + + protected ByteBufferImpl scopedPutInt(int i, int x, boolean be) { + checkIndex(i, 4); + put(i, (byte)x); + put(i + 1, (byte)(x >>> 8)); + put(i + 2, (byte)(x >>> 16)); + put(i + 3, (byte)(x >>> 24)); + return this; + } + + protected long scopedGetLong(int i, boolean be) { + checkIndex(i, 8); + long part1 = (get(i) & 0xffL); + long part2 = (get(i + 1) & 0xffL); + long part3 = (get(i + 2) & 0xffL); + long part4 = (get(i + 3) & 0xffL); + long part5 = (get(i + 4) & 0xffL); + long part6 = (get(i + 5) & 0xffL); + long part7 = (get(i + 6) & 0xffL); + long part8 = (get(i + 7) & 0xffL); + return ((part1 << 56) | (part2 << 48) | (part3 << 40) | (part4 << 32) | (part5 << 24) | (part6 << 16) | (part7 << 8) | part8); + } + + protected ByteBufferImpl scopedPutLong(int i, long x, boolean be) { + checkIndex(i, 8); + put(i, (byte)x); + put(i + 1, (byte)(x >>> 8)); + put(i + 2, (byte)(x >>> 16)); + put(i + 3, (byte)(x >>> 24)); + put(i + 4, (byte)(x >>> 32)); + put(i + 5, (byte)(x >>> 40)); + put(i + 6, (byte)(x >>> 48)); + put(i + 7, (byte)(x >>> 56)); + return this; + } + + protected float scopedGetFloat(int i, boolean be) { + return Float.intBitsToFloat(scopedGetInt(i, be)); + } + + protected ByteBufferImpl scopedPutFloat(int i, float x, boolean be) { + return scopedPutInt(i, Float.floatToRawIntBits(x), be); + } + + protected double scopedGetDouble(int i, boolean be) { + return Double.longBitsToDouble(scopedGetLong(i, be)); + } + + protected ByteBufferImpl scopedPutDouble(int i, double x, boolean be) { + return scopedPutLong(i, Double.doubleToRawLongBits(x), be); + } + + public char getChar() { + return (char)getShort(); + } + + public ByteBufferImpl putChar(char value) { + return putShort((short)value); + } + + public char getChar(int index) { + return (char)getShort(index); + } + + public ByteBufferImpl putChar(int index, char value) { + return putShort(index, (short)value); + } + + public abstract CharBuffer asCharBuffer(); + + public short getShort() { + return getShort(nextGetIndex(2)); + } + + public ByteBufferImpl putShort(short value) { + return putShort(nextPutIndex(2), value); + } + + public short getShort(int index) { + return scopedGetShort(applyOffset(index), bigEndian); + } + + public ByteBufferImpl putShort(int index, short value) { + return scopedPutShort(applyOffset(index), value, bigEndian); + } + + public abstract ShortBuffer asShortBuffer(); + + public int getInt() { + return getInt(nextGetIndex(4)); + } + + public ByteBufferImpl putInt(int value) { + return putInt(nextPutIndex(4), value); + } + + public int getInt(int index) { + return scopedGetInt(applyOffset(index), bigEndian); + } + + public ByteBufferImpl putInt(int index, int value) { + return scopedPutInt(applyOffset(index), value, bigEndian); + } + + public abstract IntBuffer asIntBuffer(); + + public long getLong() { + return getLong(nextPutIndex(8)); + } + + public ByteBufferImpl putLong(long value) { + return putLong(nextPutIndex(8), value); + } + + public long getLong(int index) { + return scopedGetLong(applyOffset(index), bigEndian); + } + + public ByteBufferImpl putLong(int index, long value) { + return scopedPutLong(applyOffset(index), value, bigEndian); + } + + public abstract LongBuffer asLongBuffer(); + + public float getFloat() { + return Float.intBitsToFloat(getInt()); + } + + public ByteBufferImpl putFloat(float value) { + return putInt(Float.floatToRawIntBits(value)); + } + + public float getFloat(int index) { + return Float.intBitsToFloat(getInt(index)); + } + + public ByteBufferImpl putFloat(int index, float value) { + return putInt(index, Float.floatToRawIntBits(value)); + } + + public abstract FloatBuffer asFloatBuffer(); + + public double getDouble() { + return Double.longBitsToDouble(getLong()); + } + + public ByteBufferImpl putDouble(double value) { + return putLong(Double.doubleToRawLongBits(value)); + } + + public double getDouble(int index) { + return Double.longBitsToDouble(getLong(index)); + } + + public ByteBufferImpl putDouble(int index, double value) { + return putLong(index, Double.doubleToRawLongBits(value)); + } + + public abstract DoubleBuffer asDoubleBuffer(); +} diff --git a/approximations/src/main/java/generated/java/util/CharBufferImpl.java b/approximations/src/main/java/generated/java/util/CharBufferImpl.java new file mode 100644 index 00000000..c379a2de --- /dev/null +++ b/approximations/src/main/java/generated/java/util/CharBufferImpl.java @@ -0,0 +1,436 @@ +package generated.java.util; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +import java.io.IOException; +import java.nio.*; +import java.util.stream.IntStream; + +@Approximate(java.nio.CharBuffer.class) +public abstract class CharBufferImpl + extends BufferImpl + implements Comparable, Appendable, CharSequence, ReadableImpl { + final char[] storage; + boolean isReadOnly; + + CharBufferImpl(int mark, int pos, int lim, int cap, char[] hb, int offset) + { + super(mark, pos, lim, cap); + this.storage = hb; + this.offset = offset; + } + + CharBufferImpl(int mark, int pos, int lim, int cap, char[] segment) { + this(mark, pos, lim, cap, segment, 0); + } + + CharBufferImpl(char[] hb, int cap) { + super(cap); + this.storage = hb; + this.offset = 0; + } + + @Override + Object base() { + return storage; + } + + public static CharBufferImpl allocate(int capacity) { + if (capacity < 0) + throw createCapacityException(capacity); + return new HeapCharBufferImpl(capacity, capacity); + } + + public static CharBufferImpl wrap(char[] array, + int offset, int length) + { + try { + return new HeapCharBufferImpl(array, offset, length); + } catch (IllegalArgumentException x) { + throw new IndexOutOfBoundsException(); + } + } + + public static CharBufferImpl wrap(char[] array) { + return wrap(array, 0, array.length); + } + + public int read(CharBufferImpl target) throws IOException { + int limit = limit(); + int pos = position(); + int remaining = limit - pos; + assert remaining >= 0; + if (remaining <= 0) + return -1; + + int targetRemaining = target.remaining(); + assert targetRemaining >= 0; + if (targetRemaining <= 0) + return 0; + + int n = remaining < targetRemaining ? remaining : targetRemaining; + + if (targetRemaining < remaining) + limit(pos + n); + try { + if (n > 0) + target.put(this); + } finally { + limit(limit); + } + return n; + } + + public static CharBufferImpl wrap(CharSequence csq, int start, int end) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public static CharBufferImpl wrap(CharSequence csq) { + return wrap(csq, 0, csq.length()); + } + + @Override + public abstract CharBufferImpl slice(); + + @Override + public abstract CharBufferImpl slice(int index, int length); + + @Override + public abstract CharBufferImpl duplicate(); + + public abstract CharBufferImpl asReadOnlyBuffer(); + + public char get() { + int indexWithOffset = applyOffset(nextGetIndex()); + Engine.assume(indexWithOffset < storage.length); + return storage[indexWithOffset]; + } + + public CharBufferImpl put(char c) { + int indexWithOffset = applyOffset(nextPutIndex()); + Engine.assume(indexWithOffset < storage.length); + storage[indexWithOffset] = c; + return this; + } + + public char get(int index) { + int indexWithOffset = applyOffset(checkIndex(index)); + Engine.assume(indexWithOffset < storage.length); + return storage[indexWithOffset]; + } + + char getUnchecked(int index) { + return storage[applyOffset(index)]; + } + + public CharBufferImpl put(int index, char c) { + int indexWithOffset = applyOffset(checkIndex(index)); + Engine.assume(indexWithOffset < storage.length); + storage[indexWithOffset] = c; + return this; + } + + public CharBufferImpl get(char[] dst, int offset, int length) { + checkFromIndexSize(offset, length, dst.length); + if (length > remaining()) + throw new BufferUnderflowException(); + int indexWithOffset = applyOffset(nextGetIndex(length)); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(storage, indexWithOffset, dst, offset, length); + return this; + } + + public CharBufferImpl get(char[] dst) { + return get(dst, 0, dst.length); + } + + public CharBufferImpl get(int index, char[] dst, int offset, int length) { + checkFromIndexSize(index, length, limit()); + checkFromIndexSize(offset, length, dst.length); + int indexWithOffset = applyOffset(nextGetIndex(length)); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(storage, indexWithOffset, dst, offset, length); + return this; + } + + public CharBufferImpl get(int index, char[] dst) { + return get(index, dst, 0, dst.length); + } + + public CharBufferImpl put(CharBufferImpl src) { + if (src == this) + throw createSameBufferException(); + if (isReadOnly()) + throw new ReadOnlyBufferException(); + + int srcPos = src.position(); + int srcLim = src.limit(); + int srcRem = (srcPos <= srcLim ? srcLim - srcPos : 0); + int pos = position(); + int lim = limit(); + int rem = (pos <= lim ? lim - pos : 0); + + if (srcRem > rem) + throw new BufferOverflowException(); + + putBuffer(pos, src, srcPos, srcRem); + + position(pos + srcRem); + src.position(srcPos + srcRem); + + return this; + } + + public CharBufferImpl put(int index, CharBufferImpl src, int offset, int length) { + checkFromIndexSize(index, length, limit()); + checkFromIndexSize(offset, length, src.limit()); + if (isReadOnly()) + throw new ReadOnlyBufferException(); + + putBuffer(index, src, offset, length); + + return this; + } + + void putBuffer(int pos, CharBufferImpl src, int srcPos, int n) { + if (src.isAddressable()) { + Object base = base(); + assert base != null || isDirect(); + int indexWithOffset = applyOffset(pos); + int srcIndexWithOffset = src.applyOffset(srcPos); + Engine.assume(indexWithOffset + n < storage.length); + Engine.assume(srcIndexWithOffset + n < src.storage.length); + LibSLRuntime.ArrayActions.copy(src.storage, srcIndexWithOffset, storage, indexWithOffset, n); + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + public CharBufferImpl put(char[] src, int offset, int length) { + checkFromIndexSize(offset, length, src.length); + if (length > remaining()) + throw new BufferOverflowException(); + int indexWithOffset = applyOffset(nextPutIndex(length)); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(src, offset, storage, indexWithOffset, length); + return this; + } + + public final CharBufferImpl put(char[] src) { + return put(src, 0, src.length); + } + + public CharBufferImpl put(int index, char[] src, int offset, int length) { + if (isReadOnly()) + throw new ReadOnlyBufferException(); + checkFromIndexSize(index, length, limit()); + checkFromIndexSize(offset, length, src.length); + int indexWithOffset = applyOffset(index); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(src, offset, storage, indexWithOffset, length); + return this; + } + + public CharBufferImpl put(int index, char[] src) { + return put(index, src, 0, src.length); + } + + public CharBufferImpl put(String src, int start, int end) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public final CharBufferImpl put(String src) { + return put(src, 0, src.length()); + } + + public final boolean hasArray() { + return (storage != null) && !isReadOnly; + } + + public final char[] array() { + if (storage == null) + throw new UnsupportedOperationException(); + if (isReadOnly) + throw new ReadOnlyBufferException(); + return storage; + } + + public final int arrayOffset() { + if (storage == null) + throw new UnsupportedOperationException(); + if (isReadOnly) + throw new ReadOnlyBufferException(); + return offset; + } + + @Override + public final CharBufferImpl position(int newPosition) { + super.position(newPosition); + return this; + } + + @Override + public final CharBufferImpl limit(int newLimit) { + super.limit(newLimit); + return this; + } + + @Override + public final CharBufferImpl mark() { + super.mark(); + return this; + } + + @Override + public final CharBufferImpl reset() { + super.reset(); + return this; + } + + @Override + public final CharBufferImpl clear() { + super.clear(); + return this; + } + + @Override + public final CharBufferImpl flip() { + super.flip(); + return this; + } + + @Override + public final CharBufferImpl rewind() { + super.rewind(); + return this; + } + + public CharBufferImpl compact() { + int pos = position(); + int lim = limit(); + assert (pos <= lim); + int rem = lim - pos; + int srcIndexWithOffset = applyOffset(pos); + int dstIndexWithOffset = applyOffset(0); + Engine.assume(srcIndexWithOffset + rem < storage.length); + Engine.assume(dstIndexWithOffset + rem < storage.length); + LibSLRuntime.ArrayActions.copy(storage, srcIndexWithOffset, storage, dstIndexWithOffset, rem); + position(rem); + limit(capacity()); + discardMark(); + return this; + } + + public abstract boolean isDirect(); + + boolean isAddressable() { + return true; + } + + public int hashCode() { + int h = 1; + int p = position(); + for (int i = limit() - 1; i >= p; i--) + h = 31 * h + (int)get(i); + return h; + } + + private int mismatch(CharBufferImpl a, int aOff, CharBufferImpl b, int bOff, int length) { + for (int i = 0; i < length; i++) { + if (a.get(aOff + i) != b.get(bOff + i)) + return i; + } + return -1; + } + + public boolean equals(Object ob) { + if (this == ob) + return true; + if (!(ob instanceof CharBufferImpl)) + return false; + CharBufferImpl that = (CharBufferImpl)ob; + int thisPos = this.position(); + int thisRem = this.limit() - thisPos; + int thatPos = that.position(); + int thatRem = that.limit() - thatPos; + if (thisRem < 0 || thisRem != thatRem) + return false; + return mismatch(this, thisPos, that, thatPos, thisRem) < 0; + } + + public int compareTo(CharBufferImpl that) { + int thisPos = this.position(); + int thisRem = this.limit() - thisPos; + int thatPos = that.position(); + int thatRem = that.limit() - thatPos; + int length = thisRem < thatRem ? thisRem : thatRem; + if (length < 0) + return -1; + int i = mismatch(this, thisPos, that, thatPos, length); + if (i >= 0) { + return compare(this.get(thisPos + i), that.get(thatPos + i)); + } + return thisRem - thatRem; + } + + private static int compare(char x, char y) { return x - y; } + + public int mismatch(CharBufferImpl that) { + int thisPos = this.position(); + int thisRem = this.limit() - thisPos; + int thatPos = that.position(); + int thatRem = that.limit() - thatPos; + int length = thisRem < thatRem ? thisRem : thatRem; + if (length < 0) + return -1; + int r = mismatch(this, thisPos, that, thatPos, length); + return (r == -1 && thisRem != thatRem) ? length : r; + } + + public String toString() { + return toString(position(), limit()); + } + + abstract String toString(int start, int end); + + public final int length() { + return remaining(); + } + + public final boolean isEmpty() { + return remaining() == 0; + } + + public final char charAt(int index) { + return get(position() + checkIndex(index, 1)); + } + + public abstract CharBufferImpl subSequence(int start, int end); + + public CharBufferImpl append(CharSequence csq) { + if (csq == null) + return put("null"); + else + return put(csq.toString()); + } + + public CharBufferImpl append(CharSequence csq, int start, int end) { + CharSequence cs = (csq == null ? "null" : csq); + return put(cs.subSequence(start, end).toString()); + } + + public CharBufferImpl append(char c) { + return put(c); + } + + public abstract ByteOrder order(); + + abstract ByteOrder charRegionOrder(); + + @Override + public IntStream chars() { + throw new UnsupportedOperationException("Not implemented yet"); + } +} diff --git a/approximations/src/main/java/generated/java/util/DirectByteBufferImpl.java b/approximations/src/main/java/generated/java/util/DirectByteBufferImpl.java new file mode 100644 index 00000000..c8ba73a6 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/DirectByteBufferImpl.java @@ -0,0 +1,258 @@ +package generated.java.util; + +import jdk.internal.ref.Cleaner; +import org.jacodb.approximation.annotation.Approximate; +import runtime.LibSLRuntime; +import sun.nio.ch.DirectBuffer; + +import java.io.FileDescriptor; +import java.nio.*; + +@Approximate(stub.java.util.DirectByteBuffer.class) +public class DirectByteBufferImpl extends MappedByteBufferImpl implements DirectBuffer { + private final Object att; + + DirectByteBufferImpl(int cap) { + super(-1, 0, cap, cap, null); + storage = new byte[cap]; + LibSLRuntime.ArrayActions.fill(storage, (byte) 0); + att = null; + } + + DirectByteBufferImpl(int cap, Object ob, byte[] segment) { + super(-1, 0, cap, cap, segment); + att = ob; + } + + DirectByteBufferImpl(int cap, Object ob, FileDescriptor fd, boolean isSync, byte[] segment) { + super(-1, 0, cap, cap, fd, isSync, segment); + att = ob; + } + + protected DirectByteBufferImpl(int cap, FileDescriptor fd, boolean isSync, byte[] segment) { + super(-1, 0, cap, cap, fd, isSync, segment); + att = null; + } + + DirectByteBufferImpl(DirectBuffer db, int mark, int pos, int lim, int cap, int off, byte[] segment) { + super(mark, pos, lim, cap, segment); + offset = off; + Object attachment = db.attachment(); + att = (attachment == null ? db : attachment); + } + + @Override + Object base() { + return null; + } + + public ByteBufferImpl slice() { + int pos = this.position(); + int lim = this.limit(); + int rem = (pos <= lim ? lim - pos : 0); + int off = pos; + assert (off >= 0); + return new DirectByteBufferImpl(this, -1, 0, rem, rem, off, storage); + } + + @Override + public ByteBufferImpl slice(int index, int length) { + checkFromIndexSize(index, length, limit()); + return new DirectByteBufferImpl(this, -1, 0, length, length, index, storage); + } + + public ByteBufferImpl duplicate() { + return new DirectByteBufferImpl(this, this.markValue(), this.position(), this.limit(), this.capacity(), + 0, storage); + } + + public ByteBufferImpl asReadOnlyBuffer() { + return new DirectByteBufferRImpl(this, this.markValue(), this.position(), this.limit(), this.capacity(), + 0, storage); + } + + public long address() { + throw new UnsupportedOperationException(); + } + + @Override + public Object attachment() { + return att; + } + + @Override + public Cleaner cleaner() { + return null; + } + + public byte get() { + return super.get(); + } + + public byte get(int i) { + return super.get(i); + } + + public ByteBufferImpl get(int index, byte[] dst, int offset, int length) { + super.get(index, dst, offset, length); + return this; + } + + public ByteBufferImpl put(byte x) { + return super.put(x); + } + + public ByteBufferImpl put(int i, byte x) { + return super.put(i, x); + } + + public ByteBufferImpl put(ByteBufferImpl src) { + super.put(src); + return this; + } + + public ByteBufferImpl put(int index, ByteBufferImpl src, int offset, int length) { + super.put(index, src, offset, length); + return this; + } + + public ByteBufferImpl put(byte[] src, int offset, int length) { + super.put(src, offset, length); + return this; + } + + public ByteBufferImpl put(int index, byte[] src, int offset, int length) { + super.put(index, src, offset, length); + return this; + } + + public ByteBufferImpl compact() { + return super.compact(); + } + + public boolean isDirect() { + return true; + } + + public boolean isReadOnly() { + return false; + } + + public char getChar() { + return super.getChar(); + } + + public char getChar(int i) { + return super.getChar(i); + } + + public ByteBufferImpl putChar(char x) { return super.putChar(x); } + + public ByteBufferImpl putChar(int i, char x) { + return super.putChar(i, x); + } + + public CharBuffer asCharBuffer() { + throw new UnsupportedOperationException("Not yet implemented"); + } + + public short getShort() { + return super.getShort(); + } + + public short getShort(int i) { + return super.getShort(i); + } + + public ByteBufferImpl putShort(short x) { + return super.putShort(x); + } + + public ByteBufferImpl putShort(int i, short x) { + return super.putShort(i, x); + } + + public ShortBuffer asShortBuffer() { + throw new UnsupportedOperationException("Not yet implemented"); + } + + public int getInt() { + return super.getInt(); + } + + public int getInt(int i) { + return super.getInt(i); + } + + public ByteBufferImpl putInt(int x) { + return super.putInt(x); + } + + public ByteBufferImpl putInt(int i, int x) { + return super.putInt(i, x); + } + + public IntBuffer asIntBuffer() { + throw new UnsupportedOperationException("Not yet implemented"); + } + + public long getLong() { + return super.getLong(); + } + + public long getLong(int i) { + return super.getLong(i); + } + + public ByteBufferImpl putLong(long x) { + return super.putLong(x); + } + + public ByteBufferImpl putLong(int i, long x) { + return super.putLong(i, x); + } + + public LongBuffer asLongBuffer() { + throw new UnsupportedOperationException("Not yet implemented"); + } + + public float getFloat() { + return super.getFloat(); + } + + public float getFloat(int i) { + return super.getFloat(i); + } + + public ByteBufferImpl putFloat(float x) { + return super.putFloat(x); + } + + public ByteBufferImpl putFloat(int i, float x) { + return super.putFloat(i, x); + } + + public FloatBuffer asFloatBuffer() { + throw new UnsupportedOperationException("Not yet implemented"); + } + + public double getDouble() { + return super.getDouble(); + } + + public double getDouble(int i) { + return super.getDouble(i); + } + + public ByteBufferImpl putDouble(double x) { + return super.putDouble(x); + } + + public ByteBufferImpl putDouble(int i, double x) { + return super.putDouble(i, x); + } + + public DoubleBuffer asDoubleBuffer() { + throw new UnsupportedOperationException("Not yet implemented"); + } +} diff --git a/approximations/src/main/java/generated/java/util/DirectByteBufferRImpl.java b/approximations/src/main/java/generated/java/util/DirectByteBufferRImpl.java new file mode 100644 index 00000000..cd7b026b --- /dev/null +++ b/approximations/src/main/java/generated/java/util/DirectByteBufferRImpl.java @@ -0,0 +1,177 @@ +package generated.java.util; + +import org.jacodb.approximation.annotation.Approximate; +import sun.nio.ch.DirectBuffer; + +import java.io.FileDescriptor; +import java.nio.*; + +@Approximate(stub.java.util.DirectByteBufferR.class) +public class DirectByteBufferRImpl extends DirectByteBufferImpl implements DirectBuffer { + DirectByteBufferRImpl(int cap) { + super(cap); + this.isReadOnly = true; + } + + protected DirectByteBufferRImpl(int cap, FileDescriptor fd, boolean isSync, byte[] segment) { + super(cap, fd, isSync, segment); + this.isReadOnly = true; + } + + DirectByteBufferRImpl(DirectBuffer db, int mark, int pos, int lim, int cap, int off, byte[] segment) { + super(db, mark, pos, lim, cap, off, segment); + this.isReadOnly = true; + } + + public ByteBufferImpl slice() { + int pos = this.position(); + int lim = this.limit(); + int rem = (pos <= lim ? lim - pos : 0); + int off = pos; + assert (off >= 0); + return new DirectByteBufferRImpl(this, -1, 0, rem, rem, off, storage); + } + + @Override + public ByteBufferImpl slice(int index, int length) { + checkFromIndexSize(index, length, limit()); + return new DirectByteBufferRImpl(this, -1, 0, length, length, index, storage); + } + + public ByteBufferImpl duplicate() { + return new DirectByteBufferRImpl(this, this.markValue(), this.position(), this.limit(), this.capacity(), + 0, storage); + } + + public ByteBufferImpl asReadOnlyBuffer() { + return duplicate(); + } + + public ByteBufferImpl put(byte x) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl put(int i, byte x) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl put(ByteBufferImpl src) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl put(int index, ByteBufferImpl src, int offset, int length) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl put(byte[] src, int offset, int length) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl put(int index, byte[] src, int offset, int length) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl compact() { + throw new ReadOnlyBufferException(); + } + + public boolean isReadOnly() { + return true; + } + + private ByteBufferImpl putChar(long a, char x) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl putChar(char x) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl putChar(int i, char x) { + throw new ReadOnlyBufferException(); + } + + public CharBuffer asCharBuffer() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + private ByteBufferImpl putShort(long a, short x) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl putShort(short x) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl putShort(int i, short x) { + throw new ReadOnlyBufferException(); + } + + public ShortBuffer asShortBuffer() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + private ByteBufferImpl putInt(long a, int x) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl putInt(int x) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl putInt(int i, int x) { + throw new ReadOnlyBufferException(); + } + + public IntBuffer asIntBuffer() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + private ByteBufferImpl putLong(long a, long x) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl putLong(long x) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl putLong(int i, long x) { + throw new ReadOnlyBufferException(); + } + + public LongBuffer asLongBuffer() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + private ByteBufferImpl putFloat(long a, float x) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl putFloat(float x) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl putFloat(int i, float x) { + throw new ReadOnlyBufferException(); + } + + public FloatBuffer asFloatBuffer() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + private ByteBufferImpl putDouble(long a, double x) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl putDouble(double x) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl putDouble(int i, double x) { + throw new ReadOnlyBufferException(); + } + + public DoubleBuffer asDoubleBuffer() { + throw new UnsupportedOperationException("Not implemented yet"); + } +} diff --git a/approximations/src/main/java/generated/java/util/DirectCharBufferRUImpl.java b/approximations/src/main/java/generated/java/util/DirectCharBufferRUImpl.java new file mode 100644 index 00000000..bdf9e6d4 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/DirectCharBufferRUImpl.java @@ -0,0 +1,85 @@ +package generated.java.util; + +import org.jacodb.approximation.annotation.Approximate; +import stub.java.util.DirectCharBufferRU; +import sun.nio.ch.DirectBuffer; + +import java.nio.ReadOnlyBufferException; + +@Approximate(DirectCharBufferRU.class) +public class DirectCharBufferRUImpl extends DirectCharBufferUImpl implements DirectBuffer { + DirectCharBufferRUImpl(DirectBuffer db, int mark, int pos, int lim, int cap, int off, char[] segment) { + super(db, mark, pos, lim, cap, off, segment); + this.isReadOnly = true; + } + + public CharBufferImpl slice() { + int pos = this.position(); + int lim = this.limit(); + int rem = (pos <= lim ? lim - pos : 0); + int off = (pos << 1); + assert (off >= 0); + return new DirectCharBufferRUImpl(this, -1, 0, rem, rem, off, storage); + } + + @Override + public CharBufferImpl slice(int index, int length) { + checkFromIndexSize(index, length, limit()); + return new DirectCharBufferRUImpl(this, -1, 0, length, length, index << 1, storage); + } + + public CharBufferImpl duplicate() { + return new DirectCharBufferRUImpl(this, this.markValue(), this.position(), this.limit(), this.capacity(), + 0, storage); + } + + public CharBufferImpl asReadOnlyBuffer() { + return duplicate(); + } + + public CharBufferImpl put(char x) { + throw new ReadOnlyBufferException(); + } + + public CharBufferImpl put(int i, char x) { + throw new ReadOnlyBufferException(); + } + + public CharBufferImpl put(CharBufferImpl src) { + throw new ReadOnlyBufferException(); + } + + public CharBufferImpl put(int index, CharBufferImpl src, int offset, int length) { + throw new ReadOnlyBufferException(); + } + + public CharBufferImpl put(char[] src, int offset, int length) { + throw new ReadOnlyBufferException(); + } + + public CharBufferImpl put(int index, char[] src, int offset, int length) { + throw new ReadOnlyBufferException(); + } + + public CharBufferImpl compact() { + throw new ReadOnlyBufferException(); + } + + public boolean isReadOnly() { + return true; + } + + public String toString(int start, int end) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public CharBufferImpl subSequence(int start, int end) { + int pos = position(); + int lim = limit(); + assert (pos <= lim); + int len = lim - pos; + checkFromToIndex(start, end, len); + return new DirectCharBufferRUImpl(this, -1, pos + start, pos + end, capacity(), + offset, storage); + } +} diff --git a/approximations/src/main/java/generated/java/util/DirectCharBufferUImpl.java b/approximations/src/main/java/generated/java/util/DirectCharBufferUImpl.java new file mode 100644 index 00000000..8a26c07e --- /dev/null +++ b/approximations/src/main/java/generated/java/util/DirectCharBufferUImpl.java @@ -0,0 +1,144 @@ +package generated.java.util; + +import jdk.internal.ref.Cleaner; +import org.jacodb.approximation.annotation.Approximate; +import sun.nio.ch.DirectBuffer; + +import java.nio.*; + +@Approximate(stub.java.util.DirectCharBufferU.class) +public class DirectCharBufferUImpl extends CharBufferImpl implements DirectBuffer { + private final Object att; + + DirectCharBufferUImpl(DirectBuffer db, int mark, int pos, int lim, int cap, int off, char[] segment) { + super(mark, pos, lim, cap, segment); + offset = off; + Object attachment = db.attachment(); + att = (attachment == null ? db : attachment); + } + + public Object attachment() { + return att; + } + + public Cleaner cleaner() { return null; } + + @Override + Object base() { + return null; + } + + public CharBufferImpl slice() { + int pos = this.position(); + int lim = this.limit(); + int rem = (pos <= lim ? lim - pos : 0); + int off = pos; + assert (off >= 0); + return new DirectCharBufferUImpl(this, -1, 0, rem, rem, off, storage); + } + + @Override + public CharBufferImpl slice(int index, int length) { + checkFromIndexSize(index, length, limit()); + return new DirectCharBufferUImpl(this, -1, 0, length, length, index, storage); + } + + public CharBufferImpl duplicate() { + return new DirectCharBufferUImpl(this, this.markValue(), this.position(), this.limit(), this.capacity(), + 0, storage); + } + + public CharBufferImpl asReadOnlyBuffer() { + return new DirectCharBufferRUImpl(this, this.markValue(), this.position(), this.limit(), this.capacity(), + 0, storage); + } + + public long address() { + throw new UnsupportedOperationException(); + } + + public char get() { + return super.get(); + } + + public char get(int i) { + return super.get(i); + } + + char getUnchecked(int i) { + return super.getUnchecked(i); + } + + public CharBufferImpl get(char[] dst, int offset, int length) { + super.get(dst, offset, length); + return this; + } + + public CharBufferImpl get(int index, char[] dst, int offset, int length) { + super.get(index, dst, offset, length); + return this; + } + + public CharBufferImpl put(char x) { + return super.put(x); + } + + public CharBufferImpl put(int i, char x) { + return super.put(i, x); + } + + public CharBufferImpl put(CharBufferImpl src) { + super.put(src); + return this; + } + + public CharBufferImpl put(int index, CharBufferImpl src, int offset, int length) { + super.put(index, src, offset, length); + return this; + } + + public CharBufferImpl put(char[] src, int offset, int length) { + super.put(src, offset, length); + return this; + } + + public CharBufferImpl put(int index, char[] src, int offset, int length) { + super.put(index, src, offset, length); + return this; + } + + public CharBufferImpl compact() { + return super.compact(); + } + + public boolean isDirect() { + return true; + } + + public boolean isReadOnly() { + return false; + } + + public String toString(int start, int end) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public CharBufferImpl subSequence(int start, int end) { + int pos = position(); + int lim = limit(); + assert (pos <= lim); + int len = lim - pos; + checkFromToIndex(start, end, len); + return new DirectCharBufferUImpl(this, -1, pos + start, pos + end, capacity(), + offset, storage); + } + + public ByteOrder order() { + return ((ByteOrder.nativeOrder() != ByteOrder.BIG_ENDIAN) + ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN); + } + + ByteOrder charRegionOrder() { + return order(); + } +} diff --git a/approximations/src/main/java/generated/java/util/DirectFloatBufferUImpl.java b/approximations/src/main/java/generated/java/util/DirectFloatBufferUImpl.java new file mode 100644 index 00000000..23cf9576 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/DirectFloatBufferUImpl.java @@ -0,0 +1,121 @@ +package generated.java.util; + +import jdk.internal.ref.Cleaner; +import org.jacodb.approximation.annotation.Approximate; +import sun.nio.ch.DirectBuffer; + +import java.nio.ByteOrder; + +@Approximate(stub.java.util.DirectFloatBufferU.class) +public class DirectFloatBufferUImpl extends FloatBufferImpl implements DirectBuffer { + private final Object att; + + public Object attachment() { + return att; + } + + public Cleaner cleaner() { return null; } + + DirectFloatBufferUImpl(DirectBuffer db, int mark, int pos, int lim, int cap, int off, float[] segment) { + super(mark, pos, lim, cap, segment); + offset = off; + Object attachment = db.attachment(); + att = (attachment == null ? db : attachment); + } + + @Override + Object base() { + return null; + } + + public FloatBufferImpl slice() { + int pos = this.position(); + int lim = this.limit(); + int rem = (pos <= lim ? lim - pos : 0); + int off = pos; + assert (off >= 0); + return new DirectFloatBufferUImpl(this, -1, 0, rem, rem, off, storage); + } + + @Override + public FloatBufferImpl slice(int index, int length) { + checkFromIndexSize(index, length, limit()); + return new DirectFloatBufferUImpl(this, -1, 0, length, length, index, storage); + } + + public FloatBufferImpl duplicate() { + return new DirectFloatBufferUImpl(this, this.markValue(), this.position(), this.limit(), this.capacity(), + 0, storage); + } + + public FloatBufferImpl asReadOnlyBuffer() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public long address() { + throw new UnsupportedOperationException(); + } + + public float get() { + return super.get(); + } + + public float get(int i) { + return super.get(i); + } + + public FloatBufferImpl get(float[] dst, int offset, int length) { + super.get(dst, offset, length); + return this; + } + + public FloatBufferImpl get(int index, float[] dst, int offset, int length) { + super.get(index, dst, offset, length); + return this; + } + + public FloatBufferImpl put(float x) { + return super.put(x); + } + + public FloatBufferImpl put(int i, float x) { + return super.put(i, x); + } + + public FloatBufferImpl put(FloatBufferImpl src) { + super.put(src); + return this; + } + + public FloatBufferImpl put(int index, FloatBufferImpl src, int offset, int length) { + super.put(index, src, offset, length); + return this; + } + + public FloatBufferImpl put(float[] src, int offset, int length) { + super.put(src, offset, length); + return this; + } + + public FloatBufferImpl put(int index, float[] src, int offset, int length) { + super.put(index, src, offset, length); + return this; + } + + public FloatBufferImpl compact() { + return super.compact(); + } + + public boolean isDirect() { + return true; + } + + public boolean isReadOnly() { + return false; + } + + public ByteOrder order() { + return ((ByteOrder.nativeOrder() != ByteOrder.BIG_ENDIAN) + ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN); + } +} diff --git a/approximations/src/main/java/generated/java/util/DirectIntBufferRUImpl.java b/approximations/src/main/java/generated/java/util/DirectIntBufferRUImpl.java new file mode 100644 index 00000000..3a76d0c3 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/DirectIntBufferRUImpl.java @@ -0,0 +1,85 @@ +package generated.java.util; + +import org.jacodb.approximation.annotation.Approximate; +import sun.nio.ch.DirectBuffer; + +import java.nio.*; + +@Approximate(stub.java.util.DirectIntBufferRU.class) +public class DirectIntBufferRUImpl extends DirectIntBufferUImpl implements DirectBuffer { + DirectIntBufferRUImpl(DirectBuffer db, int mark, int pos, int lim, int cap, int off, int[] segment) { + super(db, mark, pos, lim, cap, off, segment); + this.isReadOnly = true; + } + + @Override + Object base() { + return null; + } + + public IntBufferImpl slice() { + int pos = this.position(); + int lim = this.limit(); + int rem = (pos <= lim ? lim - pos : 0); + int off = pos; + assert (off >= 0); + return new DirectIntBufferRUImpl(this, -1, 0, rem, rem, off, storage); + } + + @Override + public IntBufferImpl slice(int index, int length) { + checkFromIndexSize(index, length, limit()); + return new DirectIntBufferRUImpl(this, -1, 0, length, length, index, + storage); + } + + public IntBufferImpl duplicate() { + return new DirectIntBufferRUImpl(this, this.markValue(), this.position(), this.limit(), this.capacity(), + 0, storage); + } + + public IntBufferImpl asReadOnlyBuffer() { + return duplicate(); + } + + public IntBufferImpl put(int x) { + throw new ReadOnlyBufferException(); + } + + public IntBufferImpl put(int i, int x) { + throw new ReadOnlyBufferException(); + } + + public IntBufferImpl put(IntBufferImpl src) { + throw new ReadOnlyBufferException(); + } + + public IntBufferImpl put(int index, IntBufferImpl src, int offset, int length) { + throw new ReadOnlyBufferException(); + } + + public IntBufferImpl put(int[] src, int offset, int length) { + throw new ReadOnlyBufferException(); + } + + public IntBufferImpl put(int index, int[] src, int offset, int length) { + throw new ReadOnlyBufferException(); + } + + public IntBufferImpl compact() { + throw new ReadOnlyBufferException(); + } + + public boolean isDirect() { + return true; + } + + public boolean isReadOnly() { + return true; + } + + public ByteOrder order() { + return ((ByteOrder.nativeOrder() != ByteOrder.BIG_ENDIAN) + ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN); + } +} diff --git a/approximations/src/main/java/generated/java/util/DirectIntBufferUImpl.java b/approximations/src/main/java/generated/java/util/DirectIntBufferUImpl.java new file mode 100644 index 00000000..ff8c552e --- /dev/null +++ b/approximations/src/main/java/generated/java/util/DirectIntBufferUImpl.java @@ -0,0 +1,123 @@ +package generated.java.util; + +import jdk.internal.ref.Cleaner; +import org.jacodb.approximation.annotation.Approximate; +import stub.java.util.DirectIntBufferU; +import sun.nio.ch.DirectBuffer; + +import java.nio.*; + +@Approximate(DirectIntBufferU.class) +public class DirectIntBufferUImpl extends IntBufferImpl implements DirectBuffer { + private final Object att; + + public Object attachment() { + return att; + } + + public Cleaner cleaner() { return null; } + + DirectIntBufferUImpl(DirectBuffer db, int mark, int pos, int lim, int cap, int off, int[] segment) { + super(mark, pos, lim, cap, segment); + offset = off; + Object attachment = db.attachment(); + att = (attachment == null ? db : attachment); + } + + @Override + Object base() { + return null; + } + + public IntBufferImpl slice() { + int pos = this.position(); + int lim = this.limit(); + int rem = (pos <= lim ? lim - pos : 0); + int off = pos; + assert (off >= 0); + return new DirectIntBufferUImpl(this, -1, 0, rem, rem, off, storage); + } + + @Override + public IntBufferImpl slice(int index, int length) { + checkFromIndexSize(index, length, limit()); + return new DirectIntBufferUImpl(this, -1, 0, length, length, index, storage); + } + + public IntBufferImpl duplicate() { + return new DirectIntBufferUImpl(this, this.markValue(), this.position(), this.limit(), this.capacity(), + 0, storage); + } + + public IntBufferImpl asReadOnlyBuffer() { + return new DirectIntBufferRUImpl(this, this.markValue(), this.position(), this.limit(), this.capacity(), + 0, storage); + } + + public long address() { + throw new UnsupportedOperationException(); + } + + public int get() { + return super.get(); + } + + public int get(int i) { + return super.get(i); + } + + public IntBufferImpl get(int[] dst, int offset, int length) { + super.get(dst, offset, length); + return this; + } + + public IntBufferImpl get(int index, int[] dst, int offset, int length) { + super.get(index, dst, offset, length); + return this; + } + + public IntBufferImpl put(int x) { + return super.put(x); + } + + public IntBufferImpl put(int i, int x) { + return super.put(i, x); + } + + public IntBufferImpl put(IntBufferImpl src) { + super.put(src); + return this; + } + + public IntBufferImpl put(int index, IntBufferImpl src, int offset, int length) { + super.put(index, src, offset, length); + return this; + } + + public IntBufferImpl put(int[] src, int offset, int length) { + super.put(src, offset, length); + return this; + } + + public IntBufferImpl put(int index, int[] src, int offset, int length) { + super.put(index, src, offset, length); + return this; + } + + public IntBufferImpl compact() { + return super.compact(); + } + + public boolean isDirect() { + return true; + } + + public boolean isReadOnly() { + return false; + } + + public ByteOrder order() { + return ((ByteOrder.nativeOrder() != ByteOrder.BIG_ENDIAN) + ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN); + } +} diff --git a/approximations/src/main/java/generated/java/util/FloatBufferImpl.java b/approximations/src/main/java/generated/java/util/FloatBufferImpl.java new file mode 100644 index 00000000..fa82c838 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/FloatBufferImpl.java @@ -0,0 +1,341 @@ +package generated.java.util; + +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +import java.nio.*; + +public abstract class FloatBufferImpl extends BufferImpl implements Comparable { + final float[] storage; + boolean isReadOnly; + + FloatBufferImpl(int mark, int pos, int lim, int cap, float[] hb, int offset) { + super(mark, pos, lim, cap); + this.storage = hb; + this.offset = offset; + } + + FloatBufferImpl(int mark, int pos, int lim, int cap, float[] segment) { + this(mark, pos, lim, cap, segment, 0); + } + + FloatBufferImpl(float[] hb, int cap) { + super(cap); + this.storage = hb; + this.offset = 0; + } + + @Override + Object base() { + return storage; + } + + public static FloatBufferImpl allocate(int capacity) { + if (capacity < 0) + throw createCapacityException(capacity); + return new HeapFloatBufferImpl(capacity, capacity); + } + + public static FloatBufferImpl wrap(float[] array, int offset, int length) { + try { + return new HeapFloatBufferImpl(array, offset, length); + } catch (IllegalArgumentException x) { + throw new IndexOutOfBoundsException(); + } + } + + public static FloatBufferImpl wrap(float[] array) { + return wrap(array, 0, array.length); + } + + @Override + public abstract FloatBufferImpl slice(); + + @Override + public abstract FloatBufferImpl slice(int index, int length); + + @Override + public abstract FloatBufferImpl duplicate(); + + public abstract FloatBufferImpl asReadOnlyBuffer(); + + public float get() { + int indexWithOffset = applyOffset(nextGetIndex()); + Engine.assume(indexWithOffset < storage.length); + return storage[indexWithOffset]; + } + + public FloatBufferImpl put(float f) { + int indexWithOffset = applyOffset(nextPutIndex()); + Engine.assume(indexWithOffset < storage.length); + storage[indexWithOffset] = f; + return this; + } + + public float get(int index) { + int indexWithOffset = applyOffset(checkIndex(index)); + Engine.assume(indexWithOffset < storage.length); + return storage[indexWithOffset]; + } + + public FloatBufferImpl put(int index, float f) { + int indexWithOffset = applyOffset(checkIndex(index)); + Engine.assume(indexWithOffset < storage.length); + storage[indexWithOffset] = f; + return this; + } + + public FloatBufferImpl get(float[] dst, int offset, int length) { + checkFromIndexSize(offset, length, dst.length); + if (length > remaining()) + throw new BufferUnderflowException(); + int indexWithOffset = applyOffset(nextGetIndex(length)); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(storage, indexWithOffset, dst, offset, length); + return this; + } + + public FloatBufferImpl get(float[] dst) { + return get(dst, 0, dst.length); + } + + public FloatBufferImpl get(int index, float[] dst, int offset, int length) { + checkFromIndexSize(index, length, limit()); + checkFromIndexSize(offset, length, dst.length); + int indexWithOffset = applyOffset(nextGetIndex(length)); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(storage, indexWithOffset, dst, offset, length); + return this; + } + + public FloatBufferImpl get(int index, float[] dst) { + return get(index, dst, 0, dst.length); + } + + public FloatBufferImpl put(FloatBufferImpl src) { + if (src == this) + throw createSameBufferException(); + if (isReadOnly()) + throw new ReadOnlyBufferException(); + + int srcPos = src.position(); + int srcLim = src.limit(); + int srcRem = (srcPos <= srcLim ? srcLim - srcPos : 0); + int pos = position(); + int lim = limit(); + int rem = (pos <= lim ? lim - pos : 0); + + if (srcRem > rem) + throw new BufferOverflowException(); + + putBuffer(pos, src, srcPos, srcRem); + + position(pos + srcRem); + src.position(srcPos + srcRem); + + return this; + } + + public FloatBufferImpl put(int index, FloatBufferImpl src, int offset, int length) { + checkFromIndexSize(index, length, limit()); + checkFromIndexSize(offset, length, src.limit()); + if (isReadOnly()) + throw new ReadOnlyBufferException(); + + putBuffer(index, src, offset, length); + + return this; + } + + void putBuffer(int pos, FloatBufferImpl src, int srcPos, int n) { + Object srcBase = src.base(); + assert srcBase != null || src.isDirect(); + Object base = base(); + assert base != null || isDirect(); + int indexWithOffset = applyOffset(pos); + int srcIndexWithOffset = src.applyOffset(srcPos); + Engine.assume(indexWithOffset + n < storage.length); + Engine.assume(srcIndexWithOffset + n < src.storage.length); + LibSLRuntime.ArrayActions.copy(src.storage, srcIndexWithOffset, storage, indexWithOffset, n); + } + + public FloatBufferImpl put(float[] src, int offset, int length) { + checkFromIndexSize(offset, length, src.length); + if (length > remaining()) + throw new BufferOverflowException(); + int indexWithOffset = applyOffset(nextPutIndex(length)); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(src, offset, storage, indexWithOffset, length); + return this; + } + + public final FloatBufferImpl put(float[] src) { + return put(src, 0, src.length); + } + + public FloatBufferImpl put(int index, float[] src, int offset, int length) { + if (isReadOnly()) + throw new ReadOnlyBufferException(); + checkFromIndexSize(index, length, limit()); + checkFromIndexSize(offset, length, src.length); + int indexWithOffset = applyOffset(index); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(src, offset, storage, indexWithOffset, length); + return this; + } + + public FloatBufferImpl put(int index, float[] src) { + return put(index, src, 0, src.length); + } + + public final boolean hasArray() { + return (storage != null) && !isReadOnly; + } + + public final float[] array() { + if (storage == null) + throw new UnsupportedOperationException(); + if (isReadOnly) + throw new ReadOnlyBufferException(); + return storage; + } + + public final int arrayOffset() { + if (storage == null) + throw new UnsupportedOperationException(); + if (isReadOnly) + throw new ReadOnlyBufferException(); + return offset; + } + + @Override + public final FloatBufferImpl position(int newPosition) { + super.position(newPosition); + return this; + } + + @Override + public final FloatBufferImpl limit(int newLimit) { + super.limit(newLimit); + return this; + } + + @Override + public final FloatBufferImpl mark() { + super.mark(); + return this; + } + + @Override + public final FloatBufferImpl reset() { + super.reset(); + return this; + } + + @Override + public final FloatBufferImpl clear() { + super.clear(); + return this; + } + + @Override + public final FloatBufferImpl flip() { + super.flip(); + return this; + } + + @Override + public final FloatBufferImpl rewind() { + super.rewind(); + return this; + } + + public FloatBufferImpl compact() { + int pos = position(); + int lim = limit(); + assert (pos <= lim); + int rem = lim - pos; + int srcIndexWithOffset = applyOffset(pos); + int dstIndexWithOffset = applyOffset(0); + Engine.assume(srcIndexWithOffset + rem < storage.length); + Engine.assume(dstIndexWithOffset + rem < storage.length); + LibSLRuntime.ArrayActions.copy(storage, srcIndexWithOffset, storage, dstIndexWithOffset, rem); + position(rem); + limit(capacity()); + discardMark(); + return this; + } + + public abstract boolean isDirect(); + + public String toString() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public int hashCode() { + int h = 1; + int p = position(); + for (int i = limit() - 1; i >= p; i--) + h = 31 * h + (int)get(i); + return h; + } + + private int mismatch(FloatBufferImpl a, int aOff, FloatBufferImpl b, int bOff, int length) { + for (int i = 0; i < length; i++) { + if (a.get(aOff + i) != b.get(bOff + i)) + return i; + } + return -1; + } + + public boolean equals(Object ob) { + if (this == ob) + return true; + if (!(ob instanceof FloatBuffer)) + return false; + FloatBufferImpl that = (FloatBufferImpl)ob; + int thisPos = this.position(); + int thisRem = this.limit() - thisPos; + int thatPos = that.position(); + int thatRem = that.limit() - thatPos; + if (thisRem < 0 || thisRem != thatRem) + return false; + return mismatch(this, thisPos, that, thatPos, thisRem) < 0; + } + + public int compareTo(FloatBufferImpl that) { + int thisPos = this.position(); + int thisRem = this.limit() - thisPos; + int thatPos = that.position(); + int thatRem = that.limit() - thatPos; + int length = thisRem < thatRem ? thisRem : thatRem; + if (length < 0) + return -1; + int i = mismatch(this, thisPos, that, thatPos, length); + if (i >= 0) { + return compare(this.get(thisPos + i), that.get(thatPos + i)); + } + return thisRem - thatRem; + } + + private static int compare(float x, float y) { + return ((x < y) ? -1 : + (x > y) ? +1 : + (x == y) ? 0 : + Float.isNaN(x) ? (Float.isNaN(y) ? 0 : +1) : -1); + } + + public int mismatch(FloatBufferImpl that) { + int thisPos = this.position(); + int thisRem = this.limit() - thisPos; + int thatPos = that.position(); + int thatRem = that.limit() - thatPos; + int length = thisRem < thatRem ? thisRem : thatRem; + if (length < 0) + return -1; + int r = mismatch(this, thisPos, that, thatPos, length); + return (r == -1 && thisRem != thatRem) ? length : r; + } + + public abstract ByteOrder order(); +} diff --git a/approximations/src/main/java/generated/java/util/HashMap.java b/approximations/src/main/java/generated/java/util/HashMap.java deleted file mode 100644 index 62f04b2e..00000000 --- a/approximations/src/main/java/generated/java/util/HashMap.java +++ /dev/null @@ -1,862 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashMap.lsl:22 -// - java/util/HashMap.main.lsl:25 -// -package generated.java.util; - -import java.io.Serializable; -import java.lang.ClassCastException; -import java.lang.Cloneable; -import java.lang.IllegalArgumentException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Collection; -import java.util.ConcurrentModificationException; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.function.BiConsumer; -import java.util.function.BiFunction; -import java.util.function.Function; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * HashMapAutomaton for HashMap ~> java.util.HashMap - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.util.HashMap.class) -public class HashMap implements LibSLRuntime.Automaton, Map, Cloneable, Serializable { - private static final long serialVersionUID = 362498820763181265L; - - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public LibSLRuntime.Map> storage; - - public transient int modCount; - - @LibSLRuntime.AutomatonConstructor - public HashMap(Void __$lsl_token, final byte p0, - final LibSLRuntime.Map> p1, final int p2) { - this.__$lsl_state = p0; - this.storage = p1; - this.modCount = p2; - } - - @LibSLRuntime.AutomatonConstructor - public HashMap(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, null, 0); - } - - /** - * [CONSTRUCTOR] HashMapAutomaton::(HashMap) -> void - * Source: java/util/HashMap.main.lsl:153 - */ - public HashMap() { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.storage = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] HashMapAutomaton::(HashMap, Map) -> void - * Source: java/util/HashMap.main.lsl:159 - */ - public HashMap(Map m) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.storage = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - final Set> entrySet = ((Set>) m.entrySet()); - final Iterator> iter = entrySet.iterator(); - while (iter.hasNext()) { - final Map.Entry oEntry = iter.next(); - final Object key = oEntry.getKey(); - final Object value = oEntry.getValue(); - Map.Entry entry = null; - if (this.storage.hasKey(key)) { - entry = this.storage.get(key); - ((AbstractMap_SimpleEntry) ((Object) entry)).value = value; - } else { - entry = (stub.java.util.AbstractMap_SimpleEntry) ((Object) new AbstractMap_SimpleEntry((Void) null, - /* state = */ AbstractMap_SimpleEntry.__$lsl_States.Initialized, - /* key = */ key, - /* value = */ value - )); - this.storage.set(key, entry); - } - this.modCount += 1; - } - ; - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] HashMapAutomaton::(HashMap, int) -> void - * Source: java/util/HashMap.main.lsl:167 - */ - public HashMap(int initialCapacity) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - if (initialCapacity < 0) { - throw new IllegalArgumentException(); - } - this.storage = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] HashMapAutomaton::(HashMap, int, float) -> void - * Source: java/util/HashMap.main.lsl:179 - */ - public HashMap(int initialCapacity, float loadFactor) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - if (initialCapacity < 0) { - throw new IllegalArgumentException(); - } - if ((loadFactor <= 0) || (loadFactor != loadFactor)) { - throw new IllegalArgumentException(); - } - this.storage = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] HashMapAutomaton::_checkForComodification(int) -> void - * Source: java/util/HashMap.main.lsl:130 - */ - public void _checkForComodification(int expectedModCount) { - /* body */ { - if (this.modCount != expectedModCount) { - throw new ConcurrentModificationException(); - } - } - } - - /** - * [FUNCTION] HashMapAutomaton::clear(HashMap) -> void - * Source: java/util/HashMap.main.lsl:199 - */ - public void clear() { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.modCount += 1; - this.storage = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - } - } - - /** - * [FUNCTION] HashMapAutomaton::clone(HashMap) -> Object - * Source: java/util/HashMap.main.lsl:206 - */ - public Object clone() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final LibSLRuntime.Map> otherStorage = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - result = (java.util.HashMap) ((Object) new HashMap((Void) null, - /* state = */ HashMap.__$lsl_States.Initialized, - /* storage = */ otherStorage, - /* modCount = */ 0 - )); - final int size = this.storage.size(); - if (size != 0) { - final LibSLRuntime.Map> unseen = this.storage.duplicate(); - int c = 0; - for (c = size; c > 0; c += -1) { - final Object key = unseen.anyKey(); - final Map.Entry entry = unseen.get(key); - final Object value = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - final Map.Entry otherEntry = (stub.java.util.AbstractMap_SimpleEntry) ((Object) new AbstractMap_SimpleEntry((Void) null, - /* state = */ AbstractMap_SimpleEntry.__$lsl_States.Initialized, - /* key = */ key, - /* value = */ value - )); - otherStorage.set(key, otherEntry); - unseen.remove(key); - } - ; - } - } - return result; - } - - /** - * [FUNCTION] HashMapAutomaton::compute(HashMap, Object, BiFunction) -> Object - * Source: java/util/HashMap.main.lsl:244 - */ - public Object compute(Object key, BiFunction remappingFunction) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (remappingFunction == null) { - throw new NullPointerException(); - } - Object oldValue = null; - Map.Entry entry = null; - if (this.storage.hasKey(key)) { - entry = this.storage.get(key); - oldValue = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - } - final int expectedModCount = this.modCount; - final Object newValue = remappingFunction.apply(key, oldValue); - _checkForComodification(expectedModCount); - if (newValue == null) { - this.storage.remove(key); - } else { - if (entry != null) { - ((AbstractMap_SimpleEntry) ((Object) entry)).value = newValue; - } else { - entry = (stub.java.util.AbstractMap_SimpleEntry) ((Object) new AbstractMap_SimpleEntry((Void) null, - /* state = */ AbstractMap_SimpleEntry.__$lsl_States.Initialized, - /* key = */ key, - /* value = */ newValue - )); - this.storage.set(key, entry); - } - } - result = newValue; - } - return result; - } - - /** - * [FUNCTION] HashMapAutomaton::computeIfAbsent(HashMap, Object, Function) -> Object - * Source: java/util/HashMap.main.lsl:287 - */ - public Object computeIfAbsent(Object key, Function mappingFunction) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (mappingFunction == null) { - throw new NullPointerException(); - } - Object oldValue = null; - Map.Entry entry = null; - if (this.storage.hasKey(key)) { - entry = this.storage.get(key); - oldValue = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - } - if (oldValue != null) { - result = oldValue; - } else { - final int expectedModCount = this.modCount; - final Object newValue = mappingFunction.apply(key); - _checkForComodification(expectedModCount); - if (newValue != null) { - if (entry != null) { - ((AbstractMap_SimpleEntry) ((Object) entry)).value = newValue; - } else { - entry = (stub.java.util.AbstractMap_SimpleEntry) ((Object) new AbstractMap_SimpleEntry((Void) null, - /* state = */ AbstractMap_SimpleEntry.__$lsl_States.Initialized, - /* key = */ key, - /* value = */ newValue - )); - this.storage.set(key, entry); - } - } - result = newValue; - } - } - return result; - } - - /** - * [FUNCTION] HashMapAutomaton::computeIfPresent(HashMap, Object, BiFunction) -> Object - * Source: java/util/HashMap.main.lsl:331 - */ - public Object computeIfPresent(Object key, BiFunction remappingFunction) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (remappingFunction == null) { - throw new NullPointerException(); - } - Object oldValue = null; - Map.Entry entry = null; - if (this.storage.hasKey(key)) { - entry = this.storage.get(key); - oldValue = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - } - if (oldValue == null) { - result = oldValue; - } else { - final int expectedModCount = this.modCount; - final Object newValue = remappingFunction.apply(key, oldValue); - _checkForComodification(expectedModCount); - if (newValue == null) { - this.storage.remove(key); - } else { - if (entry != null) { - ((AbstractMap_SimpleEntry) ((Object) entry)).value = newValue; - } else { - entry = (stub.java.util.AbstractMap_SimpleEntry) ((Object) new AbstractMap_SimpleEntry((Void) null, - /* state = */ AbstractMap_SimpleEntry.__$lsl_States.Initialized, - /* key = */ key, - /* value = */ newValue - )); - this.storage.set(key, entry); - } - } - result = newValue; - } - } - return result; - } - - /** - * [FUNCTION] HashMapAutomaton::containsKey(HashMap, Object) -> boolean - * Source: java/util/HashMap.main.lsl:378 - */ - public boolean containsKey(Object key) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.storage.size() == 0) { - result = false; - } else { - result = this.storage.hasKey(key); - } - } - return result; - } - - /** - * [FUNCTION] HashMapAutomaton::containsValue(HashMap, Object) -> boolean - * Source: java/util/HashMap.main.lsl:387 - */ - public boolean containsValue(Object value) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = false; - int storageSize = this.storage.size(); - if (storageSize != 0) { - final LibSLRuntime.Map> unseen = this.storage.duplicate(); - while ((result != true) && (storageSize != 0)) { - final Object curKey = unseen.anyKey(); - final Map.Entry entry = this.storage.get(curKey); - final Object curValue = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - if (LibSLRuntime.equals(curValue, value)) { - result = true; - } - unseen.remove(curKey); - storageSize -= 1; - } - ; - } - } - return result; - } - - /** - * [FUNCTION] HashMapAutomaton::entrySet(HashMap) -> Set - * Source: java/util/HashMap.main.lsl:416 - */ - public Set entrySet() { - Set result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (stub.java.util.HashMap_EntrySet) ((Object) new HashMap_EntrySet((Void) null, - /* state = */ HashMap_EntrySet.__$lsl_States.Initialized, - /* storageRef = */ this.storage, - /* parent = */ this - )); - } - return result; - } - - /** - * [FUNCTION] HashMapAutomaton::equals(HashMap, Object) -> boolean - * Source: java/util/HashMap.main.lsl:426 - */ - public boolean equals(Object other) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (other == this) { - result = true; - } else { - result = false; - if ((other instanceof Map)) { - final Map m = ((Map) other); - int thisLength = this.storage.size(); - if (thisLength == m.size()) { - try { - result = true; - final LibSLRuntime.Map> unseen = this.storage.duplicate(); - while (result && (thisLength != 0)) { - final Object key = unseen.anyKey(); - final Map.Entry entry = this.storage.get(key); - final Object value = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - if (value == null) { - if (m.get(key) != null) { - result = false; - } else { - if (!m.containsKey(key)) { - result = false; - } - } - } else { - result = LibSLRuntime.equals(value, m.get(key)); - } - unseen.remove(key); - thisLength -= 1; - } - ; - } catch (ClassCastException __$lsl_exception) { - result = false; - } catch (NullPointerException __$lsl_exception) { - result = false; - } - ; - } - } - } - } - return result; - } - - /** - * [FUNCTION] HashMapAutomaton::forEach(HashMap, BiConsumer) -> void - * Source: java/util/HashMap.main.lsl:494 - */ - public void forEach(BiConsumer userAction) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (userAction == null) { - throw new NullPointerException(); - } - final int storageSize = this.storage.size(); - if (storageSize > 0) { - final int expectedModCount = this.modCount; - final LibSLRuntime.Map> unseen = this.storage.duplicate(); - int i = 0; - for (i = 0; i < storageSize; i += 1) { - final Object curKey = unseen.anyKey(); - final Map.Entry entry = this.storage.get(curKey); - final Object curValue = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - userAction.accept(curKey, curValue); - unseen.remove(curKey); - } - ; - _checkForComodification(expectedModCount); - } - } - } - - /** - * [FUNCTION] HashMapAutomaton::get(HashMap, Object) -> Object - * Source: java/util/HashMap.main.lsl:529 - */ - public Object get(Object key) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final Object defaultValue = null; - if (this.storage.hasKey(key)) { - final Map.Entry entry = this.storage.get(key); - result = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - } else { - result = defaultValue; - } - } - return result; - } - - /** - * [FUNCTION] HashMapAutomaton::getOrDefault(HashMap, Object, Object) -> Object - * Source: java/util/HashMap.main.lsl:536 - */ - public Object getOrDefault(Object key, Object defaultValue) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.storage.hasKey(key)) { - final Map.Entry entry = this.storage.get(key); - result = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - } else { - result = defaultValue; - } - } - return result; - } - - /** - * [FUNCTION] HashMapAutomaton::hashCode(HashMap) -> int - * Source: java/util/HashMap.main.lsl:543 - */ - public int hashCode() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = LibSLRuntime.hashCode(this.storage); - } - return result; - } - - /** - * [FUNCTION] HashMapAutomaton::isEmpty(HashMap) -> boolean - * Source: java/util/HashMap.main.lsl:549 - */ - public boolean isEmpty() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.storage.size() == 0; - } - return result; - } - - /** - * [FUNCTION] HashMapAutomaton::keySet(HashMap) -> Set - * Source: java/util/HashMap.main.lsl:555 - */ - public Set keySet() { - Set result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (stub.java.util.HashMap_KeySet) ((Object) new HashMap_KeySet((Void) null, - /* state = */ HashMap_KeySet.__$lsl_States.Initialized, - /* storageRef = */ this.storage, - /* parent = */ this - )); - } - return result; - } - - /** - * [FUNCTION] HashMapAutomaton::merge(HashMap, Object, Object, BiFunction) -> Object - * Source: java/util/HashMap.main.lsl:564 - */ - public Object merge(Object key, Object value, BiFunction remappingFunction) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (value == null) { - throw new NullPointerException(); - } - if (remappingFunction == null) { - throw new NullPointerException(); - } - Map.Entry entry = null; - if (this.storage.hasKey(key)) { - entry = this.storage.get(key); - final Object oldValue = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - if (oldValue == null) { - result = value; - } else { - final int expectedModCount = this.modCount; - result = remappingFunction.apply(oldValue, value); - _checkForComodification(expectedModCount); - } - if (result == null) { - this.storage.remove(key); - } else { - ((AbstractMap_SimpleEntry) ((Object) entry)).value = result; - } - } else { - entry = (stub.java.util.AbstractMap_SimpleEntry) ((Object) new AbstractMap_SimpleEntry((Void) null, - /* state = */ AbstractMap_SimpleEntry.__$lsl_States.Initialized, - /* key = */ key, - /* value = */ value - )); - this.storage.set(key, entry); - this.modCount += 1; - result = value; - } - } - return result; - } - - /** - * [FUNCTION] HashMapAutomaton::put(HashMap, Object, Object) -> Object - * Source: java/util/HashMap.main.lsl:607 - */ - public Object put(Object key, Object value) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = null; - Map.Entry entry = null; - if (this.storage.hasKey(key)) { - entry = this.storage.get(key); - result = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - ((AbstractMap_SimpleEntry) ((Object) entry)).value = value; - } else { - entry = (stub.java.util.AbstractMap_SimpleEntry) ((Object) new AbstractMap_SimpleEntry((Void) null, - /* state = */ AbstractMap_SimpleEntry.__$lsl_States.Initialized, - /* key = */ key, - /* value = */ value - )); - this.storage.set(key, entry); - } - this.modCount += 1; - } - return result; - } - - /** - * [FUNCTION] HashMapAutomaton::putAll(HashMap, Map) -> void - * Source: java/util/HashMap.main.lsl:633 - */ - public void putAll(Map m) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (m == null) { - throw new NullPointerException(); - } - final Set> entrySet = ((Set>) m.entrySet()); - final Iterator> iter = entrySet.iterator(); - while (iter.hasNext()) { - final Map.Entry oEntry = iter.next(); - final Object key = oEntry.getKey(); - final Object value = oEntry.getValue(); - Map.Entry entry = null; - if (this.storage.hasKey(key)) { - entry = this.storage.get(key); - ((AbstractMap_SimpleEntry) ((Object) entry)).value = value; - } else { - entry = (stub.java.util.AbstractMap_SimpleEntry) ((Object) new AbstractMap_SimpleEntry((Void) null, - /* state = */ AbstractMap_SimpleEntry.__$lsl_States.Initialized, - /* key = */ key, - /* value = */ value - )); - this.storage.set(key, entry); - } - this.modCount += 1; - } - ; - } - } - - /** - * [FUNCTION] HashMapAutomaton::putIfAbsent(HashMap, Object, Object) -> Object - * Source: java/util/HashMap.main.lsl:642 - */ - public Object putIfAbsent(Object key, Object value) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Map.Entry entry = null; - if (this.storage.hasKey(key)) { - entry = this.storage.get(key); - result = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - } else { - result = null; - entry = (stub.java.util.AbstractMap_SimpleEntry) ((Object) new AbstractMap_SimpleEntry((Void) null, - /* state = */ AbstractMap_SimpleEntry.__$lsl_States.Initialized, - /* key = */ key, - /* value = */ value - )); - this.storage.set(key, entry); - this.modCount += 1; - } - } - return result; - } - - /** - * [FUNCTION] HashMapAutomaton::remove(HashMap, Object) -> Object - * Source: java/util/HashMap.main.lsl:664 - */ - public Object remove(Object key) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.storage.hasKey(key)) { - final Map.Entry entry = this.storage.get(key); - result = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - this.storage.remove(key); - this.modCount += 1; - } else { - result = null; - } - } - return result; - } - - /** - * [FUNCTION] HashMapAutomaton::remove(HashMap, Object, Object) -> boolean - * Source: java/util/HashMap.main.lsl:682 - */ - public boolean remove(Object key, Object value) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.storage.hasKey(key)) { - final Map.Entry entry = this.storage.get(key); - final Object curValue = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - if (LibSLRuntime.equals(curValue, value)) { - this.storage.remove(key); - this.modCount += 1; - result = true; - } - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] HashMapAutomaton::replace(HashMap, Object, Object) -> Object - * Source: java/util/HashMap.main.lsl:703 - */ - public Object replace(Object key, Object value) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.storage.hasKey(key)) { - final Map.Entry entry = this.storage.get(key); - result = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - ((AbstractMap_SimpleEntry) ((Object) entry)).value = value; - } else { - result = null; - } - } - return result; - } - - /** - * [FUNCTION] HashMapAutomaton::replace(HashMap, Object, Object, Object) -> boolean - * Source: java/util/HashMap.main.lsl:719 - */ - public boolean replace(Object key, Object oldValue, Object newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = false; - if (this.storage.hasKey(key)) { - final Map.Entry entry = this.storage.get(key); - final Object curValue = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - if (LibSLRuntime.equals(curValue, oldValue)) { - ((AbstractMap_SimpleEntry) ((Object) entry)).value = newValue; - result = true; - } - } - } - return result; - } - - /** - * [FUNCTION] HashMapAutomaton::replaceAll(HashMap, BiFunction) -> void - * Source: java/util/HashMap.main.lsl:737 - */ - public void replaceAll(BiFunction function) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (function == null) { - throw new NullPointerException(); - } - final int size = this.storage.size(); - if (size > 0) { - final int expectedModCount = this.modCount; - final LibSLRuntime.Map> unseen = this.storage.duplicate(); - int i = 0; - for (i = 0; i < size; i += 1) { - final Object key = unseen.anyKey(); - final Map.Entry entry = this.storage.get(key); - ((AbstractMap_SimpleEntry) ((Object) entry)).value = function.apply(key, ((AbstractMap_SimpleEntry) ((Object) entry)).value); - unseen.remove(key); - } - ; - _checkForComodification(expectedModCount); - } - } - } - - /** - * [FUNCTION] HashMapAutomaton::size(HashMap) -> int - * Source: java/util/HashMap.main.lsl:773 - */ - public int size() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.storage.size(); - } - return result; - } - - /** - * [FUNCTION] HashMapAutomaton::toString(HashMap) -> String - * Source: java/util/HashMap.main.lsl:780 - */ - public String toString() { - String result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - int count = this.storage.size(); - if (count == 0) { - result = "{}"; - } else { - result = "{"; - final LibSLRuntime.Map> unseen = this.storage.duplicate(); - count = unseen.size(); - Engine.assume(count > 0); - while (count != 0) { - final Object key = unseen.anyKey(); - final Map.Entry entry = unseen.get(key); - unseen.remove(key); - result = result.concat(LibSLRuntime.toString(entry)); - count -= 1; - if (count != 0) { - result = result.concat(", "); - } - } - ; - result = result.concat("}"); - } - } - return result; - } - - /** - * [FUNCTION] HashMapAutomaton::values(HashMap) -> Collection - * Source: java/util/HashMap.main.lsl:818 - */ - public Collection values() { - Collection result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (stub.java.util.HashMap_Values) ((Object) new HashMap_Values((Void) null, - /* state = */ HashMap_Values.__$lsl_States.Initialized, - /* storageRef = */ this.storage, - /* parent = */ this - )); - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(HashMap.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/HashMap_EntryIterator.java b/approximations/src/main/java/generated/java/util/HashMap_EntryIterator.java deleted file mode 100644 index 995a086a..00000000 --- a/approximations/src/main/java/generated/java/util/HashMap_EntryIterator.java +++ /dev/null @@ -1,152 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashMap.lsl:99 -// - java/util/HashMap.EntryIterator.lsl:20 -// -package generated.java.util; - -import java.lang.IllegalStateException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ConcurrentModificationException; -import java.util.Iterator; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.function.Consumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * HashMap_EntryIteratorAutomaton for HashMap_EntryIterator ~> java.util.HashMap_EntryIterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.HashMap_EntryIterator.class) -public final class HashMap_EntryIterator implements LibSLRuntime.Automaton, Iterator { - static { - Engine.assume(true); - } - - public HashMap parent; - - public LibSLRuntime.Map> unseen; - - public int expectedModCount; - - public Object currentKey; - - @LibSLRuntime.AutomatonConstructor - public HashMap_EntryIterator(Void __$lsl_token, final byte p0, final HashMap p1, - final LibSLRuntime.Map> p2, final int p3, - final Object p4) { - this.parent = p1; - this.unseen = p2; - this.expectedModCount = p3; - this.currentKey = p4; - } - - @LibSLRuntime.AutomatonConstructor - public HashMap_EntryIterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, null, 0, null); - } - - /** - * [SUBROUTINE] HashMap_EntryIteratorAutomaton::_checkForComodification() -> void - * Source: java/util/HashMap.EntryIterator.lsl:53 - */ - private void _checkForComodification() { - /* body */ { - final int modCount = ((HashMap) ((Object) this.parent)).modCount; - if (modCount != this.expectedModCount) { - throw new ConcurrentModificationException(); - } - } - } - - /** - * [FUNCTION] HashMap_EntryIteratorAutomaton::forEachRemaining(HashMap_EntryIterator, Consumer) -> void - * Source: java/util/HashMap.EntryIterator.lsl:68 - */ - public void forEachRemaining(Consumer userAction) { - /* body */ { - if (userAction == null) { - throw new NullPointerException(); - } - int size = this.unseen.size(); - if (size != 0) { - while ((size != 0) && (((HashMap) ((Object) this.parent)).modCount == this.expectedModCount)) { - _checkForComodification(); - final Object curKey = this.unseen.anyKey(); - userAction.accept(this.unseen.get(curKey)); - this.unseen.remove(curKey); - size -= 1; - } - ; - } - } - } - - /** - * [FUNCTION] HashMap_EntryIteratorAutomaton::hasNext(HashMap_EntryIterator) -> boolean - * Source: java/util/HashMap.EntryIterator.lsl:96 - */ - public final boolean hasNext() { - boolean result = false; - /* body */ { - result = this.unseen.size() != 0; - } - return result; - } - - /** - * [FUNCTION] HashMap_EntryIteratorAutomaton::next(HashMap_EntryIterator) -> Map_Entry - * Source: java/util/HashMap.EntryIterator.lsl:102 - */ - public final Map.Entry next() { - Map.Entry result = null; - /* body */ { - _checkForComodification(); - if (this.unseen.size() == 0) { - throw new NoSuchElementException(); - } - final Object curKey = this.unseen.anyKey(); - result = this.unseen.get(curKey); - this.unseen.remove(curKey); - this.currentKey = curKey; - } - return result; - } - - /** - * [FUNCTION] HashMap_EntryIteratorAutomaton::remove(HashMap_EntryIterator) -> void - * Source: java/util/HashMap.EntryIterator.lsl:119 - */ - public final void remove() { - /* body */ { - Engine.assume(this.parent != null); - final Object key = this.currentKey; - if (key == null) { - throw new IllegalStateException(); - } - _checkForComodification(); - ((HashMap) ((Object) this.parent)).storage.remove(key); - ((HashMap) ((Object) this.parent)).modCount += 1; - this.unseen.remove(key); - this.expectedModCount = ((HashMap) ((Object) this.parent)).modCount; - this.currentKey = null; - } - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(HashMap_EntryIterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/HashMap_EntrySet.java b/approximations/src/main/java/generated/java/util/HashMap_EntrySet.java deleted file mode 100644 index 227dc08f..00000000 --- a/approximations/src/main/java/generated/java/util/HashMap_EntrySet.java +++ /dev/null @@ -1,600 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashMap.lsl:90 -// - java/util/HashMap.EntrySet.lsl:27 -// -package generated.java.util; - -import java.lang.ClassCastException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.UnsupportedOperationException; -import java.lang.Void; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.Spliterator; -import java.util.function.Consumer; -import java.util.function.IntFunction; -import java.util.function.Predicate; -import java.util.stream.Stream; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; -import stub.java.util.stream.StreamLSL; - -/** - * HashMap_EntrySetAutomaton for HashMap_EntrySet ~> java.util.HashMap_EntrySet - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.HashMap_EntrySet.class) -public final class HashMap_EntrySet implements LibSLRuntime.Automaton { - static { - Engine.assume(true); - } - - public LibSLRuntime.Map> storageRef; - - public HashMap parent; - - @LibSLRuntime.AutomatonConstructor - public HashMap_EntrySet(Void __$lsl_token, final byte p0, - final LibSLRuntime.Map> p1, final HashMap p2) { - this.storageRef = p1; - this.parent = p2; - } - - @LibSLRuntime.AutomatonConstructor - public HashMap_EntrySet(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, null); - } - - /** - * [SUBROUTINE] HashMap_EntrySetAutomaton::_mapToEntryArray() -> array> - * Source: java/util/HashMap.EntrySet.lsl:80 - */ - private Map.Entry[] _mapToEntryArray() { - Map.Entry[] result = null; - /* body */ { - final int storageSize = this.storageRef.size(); - result = new Map.Entry[storageSize]; - if (storageSize != 0) { - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < storageSize; i += 1) { - final Object curKey = unseen.anyKey(); - result[i] = this.storageRef.get(curKey); - unseen.remove(curKey); - } - ; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySetAutomaton::add(HashMap_EntrySet, Object) -> boolean - * Source: java/util/HashMap.EntrySet.lsl:115 - */ - public boolean add(Object e) { - boolean result = false; - /* body */ { - if (true) { - throw new UnsupportedOperationException(); - } - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySetAutomaton::addAll(HashMap_EntrySet, Collection) -> boolean - * Source: java/util/HashMap.EntrySet.lsl:123 - */ - public boolean addAll(Collection c) { - boolean result = false; - /* body */ { - if (true) { - throw new UnsupportedOperationException(); - } - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySetAutomaton::clear(HashMap_EntrySet) -> void - * Source: java/util/HashMap.EntrySet.lsl:130 - */ - public final void clear() { - /* body */ { - ((HashMap) ((Object) this.parent)).modCount += 1; - final LibSLRuntime.Map> newStorage = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - this.storageRef = newStorage; - ((HashMap) ((Object) this.parent)).storage = newStorage; - } - } - - /** - * [FUNCTION] HashMap_EntrySetAutomaton::contains(HashMap_EntrySet, Object) -> boolean - * Source: java/util/HashMap.EntrySet.lsl:141 - */ - public final boolean contains(Object o) { - boolean result = false; - /* body */ { - result = false; - if ((o instanceof Map.Entry)) { - final Map.Entry oEntry = ((Map.Entry) o); - final Object key = oEntry.getKey(); - if (this.storageRef.hasKey(key)) { - final Map.Entry entry = this.storageRef.get(key); - result = LibSLRuntime.equals(entry, oEntry); - } - } - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySetAutomaton::containsAll(HashMap_EntrySet, Collection) -> boolean - * Source: java/util/HashMap.EntrySet.lsl:160 - */ - public boolean containsAll(Collection c) { - boolean result = false; - /* body */ { - result = true; - final Iterator> iter = ((Iterator>) c.iterator()); - while (result && iter.hasNext()) { - final Map.Entry oEntry = iter.next(); - final Object key = oEntry.getKey(); - if (this.storageRef.hasKey(key)) { - final Map.Entry entry = this.storageRef.get(key); - result = LibSLRuntime.equals(entry, oEntry); - } else { - result = false; - } - } - ; - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySetAutomaton::equals(HashMap_EntrySet, Object) -> boolean - * Source: java/util/HashMap.EntrySet.lsl:191 - */ - public boolean equals(Object other) { - boolean result = false; - /* body */ { - if (other == this) { - result = true; - } else { - result = false; - if ((other instanceof Set)) { - final Collection c = ((Collection) other); - if (this.storageRef.size() == c.size()) { - try { - result = true; - final Iterator> iter = ((Iterator>) c.iterator()); - while (result && iter.hasNext()) { - final Map.Entry oEntry = iter.next(); - final Object key = oEntry.getKey(); - if (this.storageRef.hasKey(key)) { - final Map.Entry entry = this.storageRef.get(key); - result = LibSLRuntime.equals(entry, oEntry); - } else { - result = false; - } - } - ; - } catch (ClassCastException __$lsl_exception) { - result = false; - } catch (NullPointerException __$lsl_exception) { - result = false; - } - ; - } - } - } - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySetAutomaton::forEach(HashMap_EntrySet, Consumer) -> void - * Source: java/util/HashMap.EntrySet.lsl:236 - */ - public final void forEach(Consumer userAction) { - /* body */ { - if (userAction == null) { - throw new NullPointerException(); - } - final int size = this.storageRef.size(); - if (size > 0) { - final int expectedModCount = ((HashMap) ((Object) this.parent)).modCount; - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < size; i += 1) { - final Object key = unseen.anyKey(); - final Map.Entry entry = this.storageRef.get(key); - userAction.accept(entry); - unseen.remove(key); - } - ; - ((HashMap) ((Object) this.parent))._checkForComodification(expectedModCount); - } - } - } - - /** - * [FUNCTION] HashMap_EntrySetAutomaton::hashCode(HashMap_EntrySet) -> int - * Source: java/util/HashMap.EntrySet.lsl:270 - */ - public int hashCode() { - int result = 0; - /* body */ { - result = LibSLRuntime.hashCode(this.storageRef); - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySetAutomaton::isEmpty(HashMap_EntrySet) -> boolean - * Source: java/util/HashMap.EntrySet.lsl:277 - */ - public boolean isEmpty() { - boolean result = false; - /* body */ { - result = this.storageRef.size() == 0; - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySetAutomaton::iterator(HashMap_EntrySet) -> Iterator - * Source: java/util/HashMap.EntrySet.lsl:283 - */ - public final Iterator iterator() { - Iterator result = null; - /* body */ { - result = (stub.java.util.HashMap_EntryIterator) ((Object) new HashMap_EntryIterator((Void) null, - /* state = */ HashMap_EntryIterator.__$lsl_States.Initialized, - /* parent = */ this.parent, - /* unseen = */ this.storageRef.duplicate(), - /* expectedModCount = */ ((HashMap) ((Object) this.parent)).modCount, - /* currentKey = */ null - )); - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySetAutomaton::parallelStream(HashMap_EntrySet) -> Stream - * Source: java/util/HashMap.EntrySet.lsl:294 - */ - public Stream parallelStream() { - Stream result = null; - /* body */ { - final Object[] items = _mapToEntryArray(); - result = (StreamLSL) ((Object) new generated.java.util.stream.StreamLSL((Void) null, - /* state = */ generated.java.util.stream.StreamLSL.__$lsl_States.Initialized, - /* storage = */ items, - /* length = */ items.length, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ true, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySetAutomaton::remove(HashMap_EntrySet, Object) -> boolean - * Source: java/util/HashMap.EntrySet.lsl:307 - */ - public final boolean remove(Object o) { - boolean result = false; - /* body */ { - result = false; - if ((o instanceof Map.Entry)) { - final Map.Entry oEntry = ((Map.Entry) o); - final Object key = oEntry.getKey(); - if (this.storageRef.hasKey(key)) { - final Map.Entry entry = this.storageRef.get(key); - if (LibSLRuntime.equals(entry, oEntry)) { - this.storageRef.remove(key); - ((HashMap) ((Object) this.parent)).modCount += 1; - result = true; - } - } - } - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySetAutomaton::removeAll(HashMap_EntrySet, Collection) -> boolean - * Source: java/util/HashMap.EntrySet.lsl:332 - */ - public boolean removeAll(Collection c) { - boolean result = false; - /* body */ { - if (c == null) { - throw new NullPointerException(); - } - result = false; - final int startStorageSize = this.storageRef.size(); - final int cSize = c.size(); - if ((startStorageSize != 0) && (cSize != 0)) { - if (startStorageSize > cSize) { - final Iterator> iter = ((Iterator>) c.iterator()); - while (iter.hasNext()) { - final Map.Entry entry = iter.next(); - final Object curKey = ((AbstractMap_SimpleEntry) ((Object) entry)).key; - if (this.storageRef.hasKey(curKey)) { - if (LibSLRuntime.equals(entry, this.storageRef.get(curKey))) { - this.storageRef.remove(curKey); - ((HashMap) ((Object) this.parent)).modCount += 1; - } - } - } - ; - } else { - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < startStorageSize; i += 1) { - final Object curKey = unseen.anyKey(); - final Map.Entry entry = this.storageRef.get(curKey); - if (c.contains(entry)) { - this.storageRef.remove(curKey); - ((HashMap) ((Object) this.parent)).modCount += 1; - } - unseen.remove(curKey); - } - ; - } - final int resultStorageSize = this.storageRef.size(); - result = startStorageSize != resultStorageSize; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySetAutomaton::removeIf(HashMap_EntrySet, Predicate) -> boolean - * Source: java/util/HashMap.EntrySet.lsl:396 - */ - public boolean removeIf(Predicate filter) { - boolean result = false; - /* body */ { - if (filter == null) { - throw new NullPointerException(); - } - result = false; - final int startStorageSize = this.storageRef.size(); - if (startStorageSize != 0) { - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < startStorageSize; i += 1) { - final Object curKey = unseen.anyKey(); - final Map.Entry entry = unseen.get(curKey); - if (filter.test(entry)) { - this.storageRef.remove(curKey); - ((HashMap) ((Object) this.parent)).modCount += 1; - } - unseen.remove(curKey); - } - ; - final int resultStorageSize = this.storageRef.size(); - result = startStorageSize != resultStorageSize; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySetAutomaton::retainAll(HashMap_EntrySet, Collection) -> boolean - * Source: java/util/HashMap.EntrySet.lsl:433 - */ - public boolean retainAll(Collection c) { - boolean result = false; - /* body */ { - if (c == null) { - throw new NullPointerException(); - } - result = false; - final int startStorageSize = this.storageRef.size(); - final int cSize = c.size(); - if ((startStorageSize != 0) && (cSize != 0)) { - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < startStorageSize; i += 1) { - final Object curKey = unseen.anyKey(); - final Map.Entry entry = unseen.get(curKey); - if (!c.contains(entry)) { - this.storageRef.remove(curKey); - ((HashMap) ((Object) this.parent)).modCount += 1; - } - } - ; - final int resultStorageSize = this.storageRef.size(); - result = startStorageSize != resultStorageSize; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySetAutomaton::size(HashMap_EntrySet) -> int - * Source: java/util/HashMap.EntrySet.lsl:469 - */ - public final int size() { - int result = 0; - /* body */ { - result = this.storageRef.size(); - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySetAutomaton::spliterator(HashMap_EntrySet) -> Spliterator - * Source: java/util/HashMap.EntrySet.lsl:475 - */ - public final Spliterator spliterator() { - Spliterator result = null; - /* body */ { - result = (stub.java.util.HashMap_EntrySpliterator) ((Object) new HashMap_EntrySpliterator((Void) null, - /* state = */ HashMap_EntrySpliterator.__$lsl_States.Initialized, - /* parent = */ this.parent, - /* entryStorage = */ _mapToEntryArray(), - /* index = */ 0, - /* fence = */ -1, - /* est = */ 0, - /* expectedModCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySetAutomaton::stream(HashMap_EntrySet) -> Stream - * Source: java/util/HashMap.EntrySet.lsl:485 - */ - public Stream stream() { - Stream result = null; - /* body */ { - final Object[] items = _mapToEntryArray(); - result = (StreamLSL) ((Object) new generated.java.util.stream.StreamLSL((Void) null, - /* state = */ generated.java.util.stream.StreamLSL.__$lsl_States.Initialized, - /* storage = */ items, - /* length = */ items.length, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySetAutomaton::toArray(HashMap_EntrySet) -> array - * Source: java/util/HashMap.EntrySet.lsl:498 - */ - public Object[] toArray() { - Object[] result = null; - /* body */ { - final int len = this.storageRef.size(); - result = new Object[len]; - if (len != 0) { - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < len; i += 1) { - final Object key = unseen.anyKey(); - result[i] = unseen.get(key); - unseen.remove(key); - } - ; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySetAutomaton::toArray(HashMap_EntrySet, IntFunction) -> array - * Source: java/util/HashMap.EntrySet.lsl:526 - */ - public Object[] toArray(IntFunction generator) { - Object[] result = null; - /* body */ { - final Object[] a = ((Object[]) generator.apply(0)); - final int aLen = a.length; - final int len = this.storageRef.size(); - result = new Object[len]; - if (len != 0) { - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < len; i += 1) { - final Object key = unseen.anyKey(); - result[i] = unseen.get(key); - unseen.remove(key); - } - ; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySetAutomaton::toArray(HashMap_EntrySet, array) -> array - * Source: java/util/HashMap.EntrySet.lsl:548 - */ - public Object[] toArray(Object[] a) { - Object[] result = null; - /* body */ { - final int aLen = a.length; - final int len = this.storageRef.size(); - if (aLen < len) { - a = new Object[len]; - } - result = a; - if (len != 0) { - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < len; i += 1) { - final Object key = unseen.anyKey(); - result[i] = unseen.get(key); - unseen.remove(key); - } - ; - if (aLen > len) { - result[len] = null; - } - } - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySetAutomaton::toString(HashMap_EntrySet) -> String - * Source: java/util/HashMap.EntrySet.lsl:574 - */ - public String toString() { - String result = null; - /* body */ { - final int size = this.storageRef.size(); - if (size == 0) { - result = "[]"; - } else { - result = "["; - final int lastIndex = size - 1; - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < size; i += 1) { - final Object key = unseen.anyKey(); - final Map.Entry entry = unseen.get(key); - final Object value = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - result = result.concat(LibSLRuntime.toString(key).concat("=").concat(LibSLRuntime.toString(value))); - if (i != lastIndex) { - result = result.concat(", "); - } - unseen.remove(key); - } - ; - result = result.concat("]"); - } - } - return result; - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(HashMap_EntrySet.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/HashMap_EntrySpliterator.java b/approximations/src/main/java/generated/java/util/HashMap_EntrySpliterator.java deleted file mode 100644 index aff56770..00000000 --- a/approximations/src/main/java/generated/java/util/HashMap_EntrySpliterator.java +++ /dev/null @@ -1,220 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashMap.lsl:108 -// - java/util/HashMap.EntrySpliterator.lsl:21 -// -package generated.java.util; - -import generated.runtime.LibSLGlobals; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ConcurrentModificationException; -import java.util.Map; -import java.util.Spliterator; -import java.util.function.Consumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * HashMap_EntrySpliteratorAutomaton for HashMap_EntrySpliterator ~> java.util.HashMap_EntrySpliterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.HashMap_EntrySpliterator.class) -public final class HashMap_EntrySpliterator implements LibSLRuntime.Automaton, Spliterator { - static { - Engine.assume(true); - } - - public HashMap parent; - - public Map.Entry[] entryStorage; - - public int index; - - public int fence; - - public int est; - - public int expectedModCount; - - @LibSLRuntime.AutomatonConstructor - public HashMap_EntrySpliterator(Void __$lsl_token, final byte p0, final HashMap p1, - final Map.Entry[] p2, final int p3, final int p4, final int p5, - final int p6) { - this.parent = p1; - this.entryStorage = p2; - this.index = p3; - this.fence = p4; - this.est = p5; - this.expectedModCount = p6; - } - - @LibSLRuntime.AutomatonConstructor - public HashMap_EntrySpliterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, null, 0, -1, 0, 0); - } - - /** - * [SUBROUTINE] HashMap_EntrySpliteratorAutomaton::_getFence() -> int - * Source: java/util/HashMap.EntrySpliterator.lsl:54 - */ - private int _getFence() { - int result = 0; - /* body */ { - Engine.assume(this.parent != null); - if (this.fence < 0) { - final int storageSize = this.entryStorage.length; - this.est = storageSize; - this.fence = storageSize; - this.expectedModCount = ((HashMap) ((Object) this.parent)).modCount; - } - result = this.fence; - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySpliteratorAutomaton::characteristics(HashMap_EntrySpliterator) -> int - * Source: java/util/HashMap.EntrySpliterator.lsl:88 - */ - public int characteristics() { - int result = 0; - /* body */ { - if ((this.fence < 0) || (this.est == this.entryStorage.length)) { - result = LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_DISTINCT; - } else { - result = LibSLGlobals.SPLITERATOR_DISTINCT; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySpliteratorAutomaton::estimateSize(HashMap_EntrySpliterator) -> long - * Source: java/util/HashMap.EntrySpliterator.lsl:98 - */ - public final long estimateSize() { - long result = 0L; - /* body */ { - _getFence(); - result = ((long) this.est); - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySpliteratorAutomaton::forEachRemaining(HashMap_EntrySpliterator, Consumer) -> void - * Source: java/util/HashMap.EntrySpliterator.lsl:105 - */ - public void forEachRemaining(Consumer userAction) { - /* body */ { - if (userAction == null) { - throw new NullPointerException(); - } - int hi = this.fence; - int mc = this.expectedModCount; - int i = this.index; - final int storageSize = this.entryStorage.length; - if (hi < 0) { - mc = ((HashMap) ((Object) this.parent)).modCount; - this.expectedModCount = mc; - this.fence = storageSize; - hi = storageSize; - } - this.index = hi; - if ((storageSize > 0) && (storageSize >= hi) && (i >= 0) && (i < this.index)) { - while (i < hi) { - Map.Entry entry = entryStorage[i]; - userAction.accept(entry); - i += 1; - } - ; - if (((HashMap) ((Object) this.parent)).modCount != mc) { - throw new ConcurrentModificationException(); - } - } - } - } - - /** - * [FUNCTION] HashMap_EntrySpliteratorAutomaton::getExactSizeIfKnown(HashMap_EntrySpliterator) -> long - * Source: java/util/HashMap.EntrySpliterator.lsl:154 - */ - public long getExactSizeIfKnown() { - long result = 0L; - /* body */ { - result = _getFence() - this.index; - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySpliteratorAutomaton::tryAdvance(HashMap_EntrySpliterator, Consumer) -> boolean - * Source: java/util/HashMap.EntrySpliterator.lsl:167 - */ - public boolean tryAdvance(Consumer userAction) { - boolean result = false; - /* body */ { - if (userAction == null) { - throw new NullPointerException(); - } - int hi = _getFence(); - int i = this.index; - if (i < hi) { - this.index = i + 1; - userAction.accept(entryStorage[i]); - if (this.expectedModCount != ((HashMap) ((Object) this.parent)).modCount) { - throw new ConcurrentModificationException(); - } - result = true; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_EntrySpliteratorAutomaton::trySplit(HashMap_EntrySpliterator) -> Spliterator - * Source: java/util/HashMap.EntrySpliterator.lsl:192 - */ - public Spliterator trySplit() { - Spliterator result = null; - /* body */ { - Engine.assume(this.parent != null); - final int hi = _getFence(); - final int lo = this.index; - int mid = (hi + lo) >>> 1; - if (lo >= mid) { - result = null; - } else { - this.est = this.est >>> 1; - this.index = mid; - result = (stub.java.util.HashMap_EntrySpliterator) ((Object) new HashMap_EntrySpliterator((Void) null, - /* state = */ HashMap_EntrySpliterator.__$lsl_States.Initialized, - /* parent = */ this.parent, - /* entryStorage = */ this.entryStorage, - /* index = */ lo, - /* fence = */ mid, - /* est = */ this.est, - /* expectedModCount = */ this.expectedModCount - )); - } - } - return result; - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(HashMap_EntrySpliterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/HashMap_KeyIterator.java b/approximations/src/main/java/generated/java/util/HashMap_KeyIterator.java deleted file mode 100644 index 152c4e54..00000000 --- a/approximations/src/main/java/generated/java/util/HashMap_KeyIterator.java +++ /dev/null @@ -1,144 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashMap.lsl:72 -// - java/util/HashMap.KeyIterator.lsl:20 -// -package generated.java.util; - -import java.lang.IllegalStateException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ConcurrentModificationException; -import java.util.Iterator; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.function.Consumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * HashMap_KeyIteratorAutomaton for HashMap_KeyIterator ~> java.util.HashMap_KeyIterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.HashMap_KeyIterator.class) -public final class HashMap_KeyIterator implements LibSLRuntime.Automaton, Iterator { - static { - Engine.assume(true); - } - - public HashMap parent; - - public LibSLRuntime.Map> unseen; - - public int expectedModCount; - - public Object currentKey; - - @LibSLRuntime.AutomatonConstructor - public HashMap_KeyIterator(Void __$lsl_token, final byte p0, final HashMap p1, - final LibSLRuntime.Map> p2, final int p3, - final Object p4) { - this.parent = p1; - this.unseen = p2; - this.expectedModCount = p3; - this.currentKey = p4; - } - - @LibSLRuntime.AutomatonConstructor - public HashMap_KeyIterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, null, 0, null); - } - - /** - * [FUNCTION] HashMap_KeyIteratorAutomaton::forEachRemaining(HashMap_KeyIterator, Consumer) -> void - * Source: java/util/HashMap.KeyIterator.lsl:67 - */ - public void forEachRemaining(Consumer userAction) { - /* body */ { - if (userAction == null) { - throw new NullPointerException(); - } - int size = this.unseen.size(); - if (size != 0) { - while ((size != 0) && (((HashMap) ((Object) this.parent)).modCount == this.expectedModCount)) { - if (((HashMap) ((Object) this.parent)).modCount != this.expectedModCount) { - throw new ConcurrentModificationException(); - } - final Object key = this.unseen.anyKey(); - userAction.accept(key); - this.unseen.remove(key); - size -= 1; - } - ; - } - } - } - - /** - * [FUNCTION] HashMap_KeyIteratorAutomaton::hasNext(HashMap_KeyIterator) -> boolean - * Source: java/util/HashMap.KeyIterator.lsl:96 - */ - public final boolean hasNext() { - boolean result = false; - /* body */ { - result = this.unseen.size() != 0; - } - return result; - } - - /** - * [FUNCTION] HashMap_KeyIteratorAutomaton::next(HashMap_KeyIterator) -> Object - * Source: java/util/HashMap.KeyIterator.lsl:102 - */ - public final Object next() { - Object result = null; - /* body */ { - if (((HashMap) ((Object) this.parent)).modCount != this.expectedModCount) { - throw new ConcurrentModificationException(); - } - if (this.unseen.size() == 0) { - throw new NoSuchElementException(); - } - result = this.unseen.anyKey(); - this.unseen.remove(result); - this.currentKey = result; - } - return result; - } - - /** - * [FUNCTION] HashMap_KeyIteratorAutomaton::remove(HashMap_KeyIterator) -> void - * Source: java/util/HashMap.KeyIterator.lsl:117 - */ - public final void remove() { - /* body */ { - Engine.assume(this.parent != null); - final Object key = this.currentKey; - if (key == null) { - throw new IllegalStateException(); - } - if (((HashMap) ((Object) this.parent)).modCount != this.expectedModCount) { - throw new ConcurrentModificationException(); - } - this.unseen.remove(key); - ((HashMap) ((Object) this.parent)).storage.remove(key); - ((HashMap) ((Object) this.parent)).modCount += 1; - this.expectedModCount = ((HashMap) ((Object) this.parent)).modCount; - this.currentKey = null; - } - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(HashMap_KeyIterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/HashMap_KeySet.java b/approximations/src/main/java/generated/java/util/HashMap_KeySet.java deleted file mode 100644 index d919ba8f..00000000 --- a/approximations/src/main/java/generated/java/util/HashMap_KeySet.java +++ /dev/null @@ -1,612 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashMap.lsl:63 -// - java/util/HashMap.KeySet.lsl:27 -// -package generated.java.util; - -import java.lang.ClassCastException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.UnsupportedOperationException; -import java.lang.Void; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.Spliterator; -import java.util.function.Consumer; -import java.util.function.IntFunction; -import java.util.function.Predicate; -import java.util.stream.Stream; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; -import stub.java.util.stream.StreamLSL; - -/** - * HashMap_KeySetAutomaton for HashMap_KeySet ~> java.util.HashMap_KeySet - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.HashMap_KeySet.class) -public final class HashMap_KeySet implements LibSLRuntime.Automaton { - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public LibSLRuntime.Map> storageRef; - - public HashMap parent; - - @LibSLRuntime.AutomatonConstructor - public HashMap_KeySet(Void __$lsl_token, final byte p0, - final LibSLRuntime.Map> p1, final HashMap p2) { - this.__$lsl_state = p0; - this.storageRef = p1; - this.parent = p2; - } - - @LibSLRuntime.AutomatonConstructor - public HashMap_KeySet(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, null, null); - } - - /** - * [CONSTRUCTOR] HashMap_KeySetAutomaton::(HashMap_KeySet, HashMap) -> void - * Source: java/util/HashMap.KeySet.lsl:134 - */ - private HashMap_KeySet(HashMap _this) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - LibSLRuntime.error("Private constructor call"); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] HashMap_KeySetAutomaton::_mapToKeysArray() -> array - * Source: java/util/HashMap.KeySet.lsl:86 - */ - private Object[] _mapToKeysArray() { - Object[] result = null; - /* body */ { - final int storageSize = this.storageRef.size(); - result = new Object[storageSize]; - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < storageSize; i += 1) { - final Object curKey = unseen.anyKey(); - result[i] = curKey; - unseen.remove(curKey); - } - ; - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySetAutomaton::add(HashMap_KeySet, Object) -> boolean - * Source: java/util/HashMap.KeySet.lsl:145 - */ - public boolean add(Object e) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (true) { - throw new UnsupportedOperationException(); - } - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySetAutomaton::addAll(HashMap_KeySet, Collection) -> boolean - * Source: java/util/HashMap.KeySet.lsl:153 - */ - public boolean addAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (true) { - throw new UnsupportedOperationException(); - } - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySetAutomaton::clear(HashMap_KeySet) -> void - * Source: java/util/HashMap.KeySet.lsl:160 - */ - public final void clear() { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - ((HashMap) ((Object) this.parent)).modCount += 1; - final LibSLRuntime.Map> newStorage = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - this.storageRef = newStorage; - ((HashMap) ((Object) this.parent)).storage = newStorage; - } - } - - /** - * [FUNCTION] HashMap_KeySetAutomaton::contains(HashMap_KeySet, Object) -> boolean - * Source: java/util/HashMap.KeySet.lsl:170 - */ - public final boolean contains(Object key) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.storageRef.size() == 0) { - result = false; - } else { - result = this.storageRef.hasKey(key); - } - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySetAutomaton::containsAll(HashMap_KeySet, Collection) -> boolean - * Source: java/util/HashMap.KeySet.lsl:180 - */ - public boolean containsAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = true; - final Iterator iter = c.iterator(); - while (result && iter.hasNext()) { - final Object item = iter.next(); - result = this.storageRef.hasKey(item); - } - ; - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySetAutomaton::equals(HashMap_KeySet, Object) -> boolean - * Source: java/util/HashMap.KeySet.lsl:193 - */ - public boolean equals(Object other) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (other == this) { - result = true; - } else { - if ((other instanceof Set)) { - final Collection c = ((Collection) other); - final int cLength = c.size(); - final int thisLength = this.storageRef.size(); - if (thisLength == cLength) { - try { - result = true; - final Iterator iter = c.iterator(); - while (result && iter.hasNext()) { - final Object item = iter.next(); - result = this.storageRef.hasKey(item); - } - ; - } catch (ClassCastException __$lsl_exception) { - result = false; - } catch (NullPointerException __$lsl_exception) { - result = false; - } - ; - } else { - result = false; - } - } else { - result = false; - } - } - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySetAutomaton::forEach(HashMap_KeySet, Consumer) -> void - * Source: java/util/HashMap.KeySet.lsl:230 - */ - public final void forEach(Consumer userAction) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (userAction == null) { - throw new NullPointerException(); - } - final int storageSize = this.storageRef.size(); - if (storageSize > 0) { - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - final int expectedModCount = ((HashMap) ((Object) this.parent)).modCount; - int i = 0; - for (i = 0; i < storageSize; i += 1) { - final Object curKey = unseen.anyKey(); - userAction.accept(curKey); - unseen.remove(curKey); - } - ; - ((HashMap) ((Object) this.parent))._checkForComodification(expectedModCount); - } - } - } - - /** - * [FUNCTION] HashMap_KeySetAutomaton::hashCode(HashMap_KeySet) -> int - * Source: java/util/HashMap.KeySet.lsl:259 - */ - public int hashCode() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = LibSLRuntime.hashCode(this.storageRef); - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySetAutomaton::isEmpty(HashMap_KeySet) -> boolean - * Source: java/util/HashMap.KeySet.lsl:266 - */ - public boolean isEmpty() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.storageRef.size() == 0; - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySetAutomaton::iterator(HashMap_KeySet) -> Iterator - * Source: java/util/HashMap.KeySet.lsl:272 - */ - public final Iterator iterator() { - Iterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (stub.java.util.HashMap_KeyIterator) ((Object) new HashMap_KeyIterator((Void) null, - /* state = */ HashMap_KeyIterator.__$lsl_States.Initialized, - /* parent = */ this.parent, - /* unseen = */ this.storageRef.duplicate(), - /* expectedModCount = */ ((HashMap) ((Object) this.parent)).modCount, - /* currentKey = */ null - )); - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySetAutomaton::parallelStream(HashMap_KeySet) -> Stream - * Source: java/util/HashMap.KeySet.lsl:283 - */ - public Stream parallelStream() { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final Object[] items = _mapToKeysArray(); - result = (StreamLSL) ((Object) new generated.java.util.stream.StreamLSL((Void) null, - /* state = */ generated.java.util.stream.StreamLSL.__$lsl_States.Initialized, - /* storage = */ _mapToKeysArray(), - /* length = */ items.length, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ true, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySetAutomaton::remove(HashMap_KeySet, Object) -> boolean - * Source: java/util/HashMap.KeySet.lsl:296 - */ - public final boolean remove(Object key) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = false; - if (this.storageRef.hasKey(key)) { - this.storageRef.remove(key); - ((HashMap) ((Object) this.parent)).modCount += 1; - result = true; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySetAutomaton::removeAll(HashMap_KeySet, Collection) -> boolean - * Source: java/util/HashMap.KeySet.lsl:309 - */ - public boolean removeAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (c == null) { - throw new NullPointerException(); - } - result = false; - final int startStorageSize = this.storageRef.size(); - final int cSize = c.size(); - if ((startStorageSize != 0) && (cSize != 0)) { - if (startStorageSize > cSize) { - final Iterator iter = c.iterator(); - while (iter.hasNext()) { - final Object oKey = iter.next(); - if (this.storageRef.hasKey(oKey)) { - this.storageRef.remove(oKey); - ((HashMap) ((Object) this.parent)).modCount += 1; - } - } - ; - } else { - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < startStorageSize; i += 1) { - final Object curKey = unseen.anyKey(); - if (c.contains(curKey)) { - this.storageRef.remove(curKey); - ((HashMap) ((Object) this.parent)).modCount += 1; - } - unseen.remove(curKey); - } - ; - } - final int resultStorageSize = this.storageRef.size(); - result = startStorageSize != resultStorageSize; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySetAutomaton::removeIf(HashMap_KeySet, Predicate) -> boolean - * Source: java/util/HashMap.KeySet.lsl:368 - */ - public boolean removeIf(Predicate filter) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (filter == null) { - throw new NullPointerException(); - } - result = false; - final int startStorageSize = this.storageRef.size(); - if (startStorageSize != 0) { - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < startStorageSize; i += 1) { - final Object curKey = unseen.anyKey(); - if (filter.test(curKey)) { - this.storageRef.remove(curKey); - ((HashMap) ((Object) this.parent)).modCount += 1; - } - unseen.remove(curKey); - } - ; - final int resultStorageSize = this.storageRef.size(); - result = startStorageSize != resultStorageSize; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySetAutomaton::retainAll(HashMap_KeySet, Collection) -> boolean - * Source: java/util/HashMap.KeySet.lsl:404 - */ - public boolean retainAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (c == null) { - throw new NullPointerException(); - } - result = false; - final int startStorageSize = this.storageRef.size(); - final int cSize = c.size(); - if ((startStorageSize != 0) && (cSize != 0)) { - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < startStorageSize; i += 1) { - final Object curKey = unseen.anyKey(); - if (!c.contains(curKey)) { - this.storageRef.remove(curKey); - ((HashMap) ((Object) this.parent)).modCount += 1; - } - unseen.remove(curKey); - } - ; - final int resultStorageSize = this.storageRef.size(); - result = startStorageSize != resultStorageSize; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySetAutomaton::size(HashMap_KeySet) -> int - * Source: java/util/HashMap.KeySet.lsl:440 - */ - public final int size() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.storageRef.size(); - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySetAutomaton::spliterator(HashMap_KeySet) -> Spliterator - * Source: java/util/HashMap.KeySet.lsl:446 - */ - public final Spliterator spliterator() { - Spliterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (stub.java.util.HashMap_KeySpliterator) ((Object) new HashMap_KeySpliterator((Void) null, - /* state = */ HashMap_KeySpliterator.__$lsl_States.Initialized, - /* keysStorage = */ _mapToKeysArray(), - /* parent = */ this.parent, - /* index = */ 0, - /* fence = */ -1, - /* est = */ 0, - /* expectedModCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySetAutomaton::stream(HashMap_KeySet) -> Stream - * Source: java/util/HashMap.KeySet.lsl:456 - */ - public Stream stream() { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final Object[] items = _mapToKeysArray(); - result = (StreamLSL) ((Object) new generated.java.util.stream.StreamLSL((Void) null, - /* state = */ generated.java.util.stream.StreamLSL.__$lsl_States.Initialized, - /* storage = */ items, - /* length = */ items.length, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySetAutomaton::toArray(HashMap_KeySet) -> array - * Source: java/util/HashMap.KeySet.lsl:470 - */ - public Object[] toArray() { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int len = this.storageRef.size(); - result = new Object[len]; - if (len != 0) { - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < len; i += 1) { - final Object curKey = unseen.anyKey(); - result[i] = curKey; - unseen.remove(curKey); - } - ; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySetAutomaton::toArray(HashMap_KeySet, IntFunction) -> array - * Source: java/util/HashMap.KeySet.lsl:496 - */ - public Object[] toArray(IntFunction generator) { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final Object[] a = ((Object[]) generator.apply(0)); - final int aLen = a.length; - final int len = this.storageRef.size(); - result = new Object[len]; - if (len != 0) { - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < len; i += 1) { - final Object curKey = unseen.anyKey(); - result[i] = curKey; - unseen.remove(curKey); - } - ; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySetAutomaton::toArray(HashMap_KeySet, array) -> array - * Source: java/util/HashMap.KeySet.lsl:518 - */ - public Object[] toArray(Object[] a) { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int aLen = a.length; - final int len = this.storageRef.size(); - if (aLen < len) { - a = new Object[len]; - } - result = a; - if (len != 0) { - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < len; i += 1) { - final Object curKey = unseen.anyKey(); - result[i] = curKey; - unseen.remove(curKey); - } - ; - if (aLen > len) { - result[len] = null; - } - } - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySetAutomaton::toString(HashMap_KeySet) -> String - * Source: java/util/HashMap.KeySet.lsl:544 - */ - public String toString() { - String result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int size = this.storageRef.size(); - if (size == 0) { - result = "[]"; - } else { - result = "["; - final int lastIndex = size - 1; - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < size; i += 1) { - final Object key = unseen.anyKey(); - result = result.concat(LibSLRuntime.toString(key)); - if (i != lastIndex) { - result = result.concat(", "); - } - unseen.remove(key); - } - ; - result = result.concat("]"); - } - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(HashMap_KeySet.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/HashMap_KeySpliterator.java b/approximations/src/main/java/generated/java/util/HashMap_KeySpliterator.java deleted file mode 100644 index 9ea2bf7e..00000000 --- a/approximations/src/main/java/generated/java/util/HashMap_KeySpliterator.java +++ /dev/null @@ -1,219 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashMap.lsl:81 -// - java/util/HashMap.KeySpliterator.lsl:21 -// -package generated.java.util; - -import generated.runtime.LibSLGlobals; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ConcurrentModificationException; -import java.util.Spliterator; -import java.util.function.Consumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * HashMap_KeySpliteratorAutomaton for HashMap_KeySpliterator ~> java.util.HashMap_KeySpliterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.HashMap_KeySpliterator.class) -public final class HashMap_KeySpliterator implements LibSLRuntime.Automaton, Spliterator { - static { - Engine.assume(true); - } - - public Object[] keysStorage; - - public HashMap parent; - - public int index; - - public int fence; - - public int est; - - public int expectedModCount; - - @LibSLRuntime.AutomatonConstructor - public HashMap_KeySpliterator(Void __$lsl_token, final byte p0, final Object[] p1, - final HashMap p2, final int p3, final int p4, final int p5, final int p6) { - this.keysStorage = p1; - this.parent = p2; - this.index = p3; - this.fence = p4; - this.est = p5; - this.expectedModCount = p6; - } - - @LibSLRuntime.AutomatonConstructor - public HashMap_KeySpliterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, null, 0, -1, 0, 0); - } - - /** - * [SUBROUTINE] HashMap_KeySpliteratorAutomaton::_getFence() -> int - * Source: java/util/HashMap.KeySpliterator.lsl:54 - */ - private int _getFence() { - int result = 0; - /* body */ { - Engine.assume(this.parent != null); - if (this.fence < 0) { - final int storageSize = this.keysStorage.length; - this.est = storageSize; - this.fence = storageSize; - this.expectedModCount = ((HashMap) ((Object) this.parent)).modCount; - } - result = this.fence; - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySpliteratorAutomaton::characteristics(HashMap_KeySpliterator) -> int - * Source: java/util/HashMap.KeySpliterator.lsl:88 - */ - public int characteristics() { - int result = 0; - /* body */ { - if ((this.fence < 0) || (this.est == this.keysStorage.length)) { - result = LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_DISTINCT; - } else { - result = LibSLGlobals.SPLITERATOR_DISTINCT; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySpliteratorAutomaton::estimateSize(HashMap_KeySpliterator) -> long - * Source: java/util/HashMap.KeySpliterator.lsl:98 - */ - public final long estimateSize() { - long result = 0L; - /* body */ { - _getFence(); - result = ((long) this.est); - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySpliteratorAutomaton::forEachRemaining(HashMap_KeySpliterator, Consumer) -> void - * Source: java/util/HashMap.KeySpliterator.lsl:105 - */ - public void forEachRemaining(Consumer userAction) { - /* body */ { - if (userAction == null) { - throw new NullPointerException(); - } - int hi = this.fence; - int mc = this.expectedModCount; - int i = this.index; - final int storageSize = this.keysStorage.length; - if (hi < 0) { - this.expectedModCount = ((HashMap) ((Object) this.parent)).modCount; - mc = this.expectedModCount; - this.fence = storageSize; - hi = storageSize; - } - this.index = hi; - if ((storageSize > 0) && (storageSize >= hi) && (i >= 0) && (i < this.index)) { - while (i < hi) { - Object curKey = keysStorage[i]; - userAction.accept(curKey); - i += 1; - } - ; - final int modCount = ((HashMap) ((Object) this.parent)).modCount; - if (modCount != mc) { - throw new ConcurrentModificationException(); - } - } - } - } - - /** - * [FUNCTION] HashMap_KeySpliteratorAutomaton::getExactSizeIfKnown(HashMap_KeySpliterator) -> long - * Source: java/util/HashMap.KeySpliterator.lsl:155 - */ - public long getExactSizeIfKnown() { - long result = 0L; - /* body */ { - result = _getFence() - this.index; - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySpliteratorAutomaton::tryAdvance(HashMap_KeySpliterator, Consumer) -> boolean - * Source: java/util/HashMap.KeySpliterator.lsl:168 - */ - public boolean tryAdvance(Consumer userAction) { - boolean result = false; - /* body */ { - if (userAction == null) { - throw new NullPointerException(); - } - int hi = _getFence(); - int i = this.index; - if (i < hi) { - this.index = i + 1; - userAction.accept(keysStorage[i]); - if (this.expectedModCount != ((HashMap) ((Object) this.parent)).modCount) { - throw new ConcurrentModificationException(); - } - result = true; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_KeySpliteratorAutomaton::trySplit(HashMap_KeySpliterator) -> Spliterator - * Source: java/util/HashMap.KeySpliterator.lsl:193 - */ - public Spliterator trySplit() { - Spliterator result = null; - /* body */ { - Engine.assume(this.parent != null); - final int hi = _getFence(); - final int lo = this.index; - int mid = (hi + lo) >>> 1; - if (lo >= mid) { - result = null; - } else { - this.est = this.est >>> 1; - this.index = mid; - result = (stub.java.util.HashMap_KeySpliterator) ((Object) new HashMap_KeySpliterator((Void) null, - /* state = */ HashMap_KeySpliterator.__$lsl_States.Initialized, - /* keysStorage = */ this.keysStorage, - /* parent = */ this.parent, - /* index = */ lo, - /* fence = */ mid, - /* est = */ this.est, - /* expectedModCount = */ this.expectedModCount - )); - } - } - return result; - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(HashMap_KeySpliterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/HashMap_ValueIterator.java b/approximations/src/main/java/generated/java/util/HashMap_ValueIterator.java deleted file mode 100644 index ad052654..00000000 --- a/approximations/src/main/java/generated/java/util/HashMap_ValueIterator.java +++ /dev/null @@ -1,147 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashMap.lsl:45 -// - java/util/HashMap.ValueIterator.lsl:20 -// -package generated.java.util; - -import java.lang.IllegalStateException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ConcurrentModificationException; -import java.util.Iterator; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.function.Consumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * HashMap_ValueIteratorAutomaton for HashMap_ValueIterator ~> java.util.HashMap_ValueIterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.HashMap_ValueIterator.class) -public class HashMap_ValueIterator implements LibSLRuntime.Automaton, Iterator { - static { - Engine.assume(true); - } - - public HashMap parent; - - public LibSLRuntime.Map> unseen; - - public int expectedModCount; - - public Object currentKey; - - @LibSLRuntime.AutomatonConstructor - public HashMap_ValueIterator(Void __$lsl_token, final byte p0, final HashMap p1, - final LibSLRuntime.Map> p2, final int p3, - final Object p4) { - this.parent = p1; - this.unseen = p2; - this.expectedModCount = p3; - this.currentKey = p4; - } - - @LibSLRuntime.AutomatonConstructor - public HashMap_ValueIterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, null, 0, null); - } - - /** - * [FUNCTION] HashMap_ValueIteratorAutomaton::forEachRemaining(HashMap_ValueIterator, Consumer) -> void - * Source: java/util/HashMap.ValueIterator.lsl:67 - */ - public void forEachRemaining(Consumer userAction) { - /* body */ { - if (userAction == null) { - throw new NullPointerException(); - } - int size = this.unseen.size(); - if (size != 0) { - while ((size != 0) && (((HashMap) ((Object) this.parent)).modCount == this.expectedModCount)) { - if (((HashMap) ((Object) this.parent)).modCount != this.expectedModCount) { - throw new ConcurrentModificationException(); - } - final Object key = this.unseen.anyKey(); - final Map.Entry entry = this.unseen.get(key); - userAction.accept(((AbstractMap_SimpleEntry) ((Object) entry)).value); - this.unseen.remove(key); - size -= 1; - } - ; - } - } - } - - /** - * [FUNCTION] HashMap_ValueIteratorAutomaton::hasNext(HashMap_ValueIterator) -> boolean - * Source: java/util/HashMap.ValueIterator.lsl:99 - */ - public final boolean hasNext() { - boolean result = false; - /* body */ { - result = this.unseen.size() != 0; - } - return result; - } - - /** - * [FUNCTION] HashMap_ValueIteratorAutomaton::next(HashMap_ValueIterator) -> Object - * Source: java/util/HashMap.ValueIterator.lsl:105 - */ - public final Object next() { - Object result = null; - /* body */ { - if (((HashMap) ((Object) this.parent)).modCount != this.expectedModCount) { - throw new ConcurrentModificationException(); - } - if (this.unseen.size() == 0) { - throw new NoSuchElementException(); - } - final Object key = this.unseen.anyKey(); - final Map.Entry entry = this.unseen.get(key); - result = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - this.unseen.remove(key); - this.currentKey = key; - } - return result; - } - - /** - * [FUNCTION] HashMap_ValueIteratorAutomaton::remove(HashMap_ValueIterator) -> void - * Source: java/util/HashMap.ValueIterator.lsl:123 - */ - public final void remove() { - /* body */ { - Engine.assume(this.parent != null); - final Object key = this.currentKey; - if (this.currentKey == null) { - throw new IllegalStateException(); - } - if (((HashMap) ((Object) this.parent)).modCount != this.expectedModCount) { - throw new ConcurrentModificationException(); - } - this.unseen.remove(key); - ((HashMap) ((Object) this.parent)).storage.remove(key); - ((HashMap) ((Object) this.parent)).modCount += 1; - this.expectedModCount = ((HashMap) ((Object) this.parent)).modCount; - this.currentKey = null; - } - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(HashMap_ValueIterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/HashMap_ValueSpliterator.java b/approximations/src/main/java/generated/java/util/HashMap_ValueSpliterator.java deleted file mode 100644 index d7e22912..00000000 --- a/approximations/src/main/java/generated/java/util/HashMap_ValueSpliterator.java +++ /dev/null @@ -1,218 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashMap.lsl:54 -// - java/util/HashMap.ValueSpliterator.lsl:21 -// -package generated.java.util; - -import generated.runtime.LibSLGlobals; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ConcurrentModificationException; -import java.util.Spliterator; -import java.util.function.Consumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * HashMap_ValueSpliteratorAutomaton for HashMap_ValueSpliterator ~> java.util.HashMap_ValueSpliterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.HashMap_ValueSpliterator.class) -public final class HashMap_ValueSpliterator implements LibSLRuntime.Automaton, Spliterator { - static { - Engine.assume(true); - } - - public Object[] valuesStorage; - - public HashMap parent; - - public int index; - - public int fence; - - public int est; - - public int expectedModCount; - - @LibSLRuntime.AutomatonConstructor - public HashMap_ValueSpliterator(Void __$lsl_token, final byte p0, final Object[] p1, - final HashMap p2, final int p3, final int p4, final int p5, final int p6) { - this.valuesStorage = p1; - this.parent = p2; - this.index = p3; - this.fence = p4; - this.est = p5; - this.expectedModCount = p6; - } - - @LibSLRuntime.AutomatonConstructor - public HashMap_ValueSpliterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, null, 0, -1, 0, 0); - } - - /** - * [SUBROUTINE] HashMap_ValueSpliteratorAutomaton::_getFence() -> int - * Source: java/util/HashMap.ValueSpliterator.lsl:55 - */ - private int _getFence() { - int result = 0; - /* body */ { - Engine.assume(this.parent != null); - if (this.fence < 0) { - final int storageSize = this.valuesStorage.length; - this.est = storageSize; - this.fence = storageSize; - this.expectedModCount = ((HashMap) ((Object) this.parent)).modCount; - } - result = this.fence; - } - return result; - } - - /** - * [FUNCTION] HashMap_ValueSpliteratorAutomaton::characteristics(HashMap_ValueSpliterator) -> int - * Source: java/util/HashMap.ValueSpliterator.lsl:89 - */ - public int characteristics() { - int result = 0; - /* body */ { - if ((this.fence < 0) || (this.est == this.valuesStorage.length)) { - result = LibSLGlobals.SPLITERATOR_SIZED; - } else { - result = 0; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_ValueSpliteratorAutomaton::estimateSize(HashMap_ValueSpliterator) -> long - * Source: java/util/HashMap.ValueSpliterator.lsl:99 - */ - public final long estimateSize() { - long result = 0L; - /* body */ { - _getFence(); - result = ((long) this.est); - } - return result; - } - - /** - * [FUNCTION] HashMap_ValueSpliteratorAutomaton::forEachRemaining(HashMap_ValueSpliterator, Consumer) -> void - * Source: java/util/HashMap.ValueSpliterator.lsl:106 - */ - public void forEachRemaining(Consumer userAction) { - /* body */ { - if (userAction == null) { - throw new NullPointerException(); - } - int hi = this.fence; - int mc = this.expectedModCount; - int i = this.index; - final int storageSize = this.valuesStorage.length; - if (hi < 0) { - mc = ((HashMap) ((Object) this.parent)).modCount; - this.expectedModCount = mc; - this.fence = storageSize; - hi = storageSize; - } - this.index = hi; - if ((storageSize > 0) && (storageSize >= hi) && (i >= 0) && (i < this.index)) { - while (i < hi) { - userAction.accept(valuesStorage[i]); - i += 1; - } - ; - final int modCount = ((HashMap) ((Object) this.parent)).modCount; - if (modCount != mc) { - throw new ConcurrentModificationException(); - } - } - } - } - - /** - * [FUNCTION] HashMap_ValueSpliteratorAutomaton::getExactSizeIfKnown(HashMap_ValueSpliterator) -> long - * Source: java/util/HashMap.ValueSpliterator.lsl:156 - */ - public long getExactSizeIfKnown() { - long result = 0L; - /* body */ { - result = _getFence() - this.index; - } - return result; - } - - /** - * [FUNCTION] HashMap_ValueSpliteratorAutomaton::tryAdvance(HashMap_ValueSpliterator, Consumer) -> boolean - * Source: java/util/HashMap.ValueSpliterator.lsl:169 - */ - public boolean tryAdvance(Consumer userAction) { - boolean result = false; - /* body */ { - if (userAction == null) { - throw new NullPointerException(); - } - int hi = _getFence(); - int i = this.index; - if (i < hi) { - this.index = i + 1; - userAction.accept(valuesStorage[i]); - if (((HashMap) ((Object) this.parent)).modCount != this.expectedModCount) { - throw new ConcurrentModificationException(); - } - result = true; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_ValueSpliteratorAutomaton::trySplit(HashMap_ValueSpliterator) -> Spliterator - * Source: java/util/HashMap.ValueSpliterator.lsl:194 - */ - public Spliterator trySplit() { - Spliterator result = null; - /* body */ { - Engine.assume(this.parent != null); - final int hi = _getFence(); - final int lo = this.index; - int mid = (hi + lo) >>> 1; - if (lo >= mid) { - result = null; - } else { - this.est = this.est >>> 1; - this.index = mid; - result = (stub.java.util.HashMap_ValueSpliterator) ((Object) new HashMap_ValueSpliterator((Void) null, - /* state = */ HashMap_ValueSpliterator.__$lsl_States.Initialized, - /* valuesStorage = */ this.valuesStorage, - /* parent = */ this.parent, - /* index = */ lo, - /* fence = */ mid, - /* est = */ this.est, - /* expectedModCount = */ this.expectedModCount - )); - } - } - return result; - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(HashMap_ValueSpliterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/HashMap_Values.java b/approximations/src/main/java/generated/java/util/HashMap_Values.java deleted file mode 100644 index d18dac15..00000000 --- a/approximations/src/main/java/generated/java/util/HashMap_Values.java +++ /dev/null @@ -1,581 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashMap.lsl:36 -// - java/util/HashMap.Values.lsl:25 -// -package generated.java.util; - -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.UnsupportedOperationException; -import java.lang.Void; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; -import java.util.Spliterator; -import java.util.function.Consumer; -import java.util.function.IntFunction; -import java.util.function.Predicate; -import java.util.stream.Stream; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; -import stub.java.util.stream.StreamLSL; - -/** - * HashMap_ValuesAutomaton for HashMap_Values ~> java.util.HashMap_Values - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.HashMap_Values.class) -public class HashMap_Values implements LibSLRuntime.Automaton { - static { - Engine.assume(true); - } - - public LibSLRuntime.Map> storageRef; - - public HashMap parent; - - @LibSLRuntime.AutomatonConstructor - public HashMap_Values(Void __$lsl_token, final byte p0, - final LibSLRuntime.Map> p1, final HashMap p2) { - this.storageRef = p1; - this.parent = p2; - } - - @LibSLRuntime.AutomatonConstructor - public HashMap_Values(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, null); - } - - /** - * [SUBROUTINE] HashMap_ValuesAutomaton::_mapToValuesArray() -> array - * Source: java/util/HashMap.Values.lsl:76 - */ - private Object[] _mapToValuesArray() { - Object[] result = null; - /* body */ { - final int size = this.storageRef.size(); - result = new Object[size]; - if (size != 0) { - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < size; i += 1) { - final Object curKey = unseen.anyKey(); - final Map.Entry entry = unseen.get(curKey); - result[i] = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - unseen.remove(curKey); - } - ; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_ValuesAutomaton::add(HashMap_Values, Object) -> boolean - * Source: java/util/HashMap.Values.lsl:113 - */ - public boolean add(Object e) { - boolean result = false; - /* body */ { - if (true) { - throw new UnsupportedOperationException(); - } - } - return result; - } - - /** - * [FUNCTION] HashMap_ValuesAutomaton::addAll(HashMap_Values, Collection) -> boolean - * Source: java/util/HashMap.Values.lsl:121 - */ - public boolean addAll(Collection c) { - boolean result = false; - /* body */ { - if (true) { - throw new UnsupportedOperationException(); - } - } - return result; - } - - /** - * [FUNCTION] HashMap_ValuesAutomaton::clear(HashMap_Values) -> void - * Source: java/util/HashMap.Values.lsl:128 - */ - public final void clear() { - /* body */ { - ((HashMap) ((Object) this.parent)).modCount += 1; - final LibSLRuntime.Map> newStorage = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - ((HashMap) ((Object) this.parent)).storage = newStorage; - this.storageRef = newStorage; - } - } - - /** - * [FUNCTION] HashMap_ValuesAutomaton::contains(HashMap_Values, Object) -> boolean - * Source: java/util/HashMap.Values.lsl:138 - */ - public final boolean contains(Object value) { - boolean result = false; - /* body */ { - result = false; - int size = this.storageRef.size(); - if (size != 0) { - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - while ((result != true) && (size != 0)) { - final Object key = unseen.anyKey(); - final Map.Entry entry = unseen.get(key); - final Object curValue = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - if (LibSLRuntime.equals(curValue, value)) { - result = true; - } - unseen.remove(key); - size -= 1; - } - ; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_ValuesAutomaton::containsAll(HashMap_Values, Collection) -> boolean - * Source: java/util/HashMap.Values.lsl:170 - */ - public boolean containsAll(Collection c) { - boolean result = false; - /* body */ { - result = true; - final int thisSize = this.storageRef.size(); - if ((thisSize != 0) && (c != this)) { - Engine.assume(thisSize > 0); - final int otherSize = c.size(); - if (otherSize > 0) { - int i = 0; - final Object[] thisValues = new Object[thisSize]; - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - for (i = 0; i < thisSize; i += 1) { - final Object key = unseen.anyKey(); - final Map.Entry entry = unseen.get(key); - thisValues[i] = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - unseen.remove(key); - } - ; - final Iterator iter = c.iterator(); - while (result && iter.hasNext()) { - final Object value = iter.next(); - result = false; - i = 0; - while ((!result) && (i != thisSize)) { - result = LibSLRuntime.equals(thisValues[i], value); - i += 1; - } - ; - } - ; - } - } - } - return result; - } - - /** - * [FUNCTION] HashMap_ValuesAutomaton::forEach(HashMap_Values, Consumer) -> void - * Source: java/util/HashMap.Values.lsl:268 - */ - public final void forEach(Consumer userAction) { - /* body */ { - if (userAction == null) { - throw new NullPointerException(); - } - final int size = this.storageRef.size(); - if (size > 0) { - final int expectedModCount = ((HashMap) ((Object) this.parent)).modCount; - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < size; i += 1) { - final Object key = unseen.anyKey(); - final Map.Entry entry = unseen.get(key); - userAction.accept(((AbstractMap_SimpleEntry) ((Object) entry)).value); - unseen.remove(key); - } - ; - ((HashMap) ((Object) this.parent))._checkForComodification(expectedModCount); - } - } - } - - /** - * [FUNCTION] HashMap_ValuesAutomaton::isEmpty(HashMap_Values) -> boolean - * Source: java/util/HashMap.Values.lsl:304 - */ - public boolean isEmpty() { - boolean result = false; - /* body */ { - result = this.storageRef.size() == 0; - } - return result; - } - - /** - * [FUNCTION] HashMap_ValuesAutomaton::iterator(HashMap_Values) -> Iterator - * Source: java/util/HashMap.Values.lsl:310 - */ - public final Iterator iterator() { - Iterator result = null; - /* body */ { - result = (stub.java.util.HashMap_ValueIterator) ((Object) new HashMap_ValueIterator((Void) null, - /* state = */ HashMap_ValueIterator.__$lsl_States.Initialized, - /* parent = */ this.parent, - /* unseen = */ this.storageRef.duplicate(), - /* expectedModCount = */ ((HashMap) ((Object) this.parent)).modCount, - /* currentKey = */ null - )); - } - return result; - } - - /** - * [FUNCTION] HashMap_ValuesAutomaton::parallelStream(HashMap_Values) -> Stream - * Source: java/util/HashMap.Values.lsl:321 - */ - public Stream parallelStream() { - Stream result = null; - /* body */ { - final Object[] items = _mapToValuesArray(); - result = (StreamLSL) ((Object) new generated.java.util.stream.StreamLSL((Void) null, - /* state = */ generated.java.util.stream.StreamLSL.__$lsl_States.Initialized, - /* storage = */ items, - /* length = */ items.length, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ true, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] HashMap_ValuesAutomaton::remove(HashMap_Values, Object) -> boolean - * Source: java/util/HashMap.Values.lsl:335 - */ - public boolean remove(Object value) { - boolean result = false; - /* body */ { - result = false; - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int thisSize = this.storageRef.size(); - int i = 0; - if (value == null) { - while ((result != true) && (thisSize != 0)) { - final Object curKey = unseen.anyKey(); - final Map.Entry entry = unseen.get(curKey); - final Object curValue = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - if (curValue == null) { - this.storageRef.remove(curKey); - result = true; - ((HashMap) ((Object) this.parent)).modCount += 1; - } - unseen.remove(curKey); - thisSize -= 1; - } - ; - } else { - while ((result != true) && (thisSize != 0)) { - final Object curKey = unseen.anyKey(); - final Map.Entry entry = unseen.get(curKey); - final Object curValue = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - if (LibSLRuntime.equals(value, curValue)) { - this.storageRef.remove(curKey); - result = true; - ((HashMap) ((Object) this.parent)).modCount += 1; - } - unseen.remove(curKey); - thisSize -= 1; - } - ; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_ValuesAutomaton::removeAll(HashMap_Values, Collection) -> boolean - * Source: java/util/HashMap.Values.lsl:392 - */ - public boolean removeAll(Collection c) { - boolean result = false; - /* body */ { - if (c == null) { - throw new NullPointerException(); - } - result = false; - final int startStorageSize = this.storageRef.size(); - final int cSize = c.size(); - if ((startStorageSize != 0) && (cSize != 0)) { - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < startStorageSize; i += 1) { - final Object curKey = unseen.anyKey(); - final Map.Entry entry = unseen.get(curKey); - final Object curValue = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - if (c.contains(curValue)) { - this.storageRef.remove(curKey); - ((HashMap) ((Object) this.parent)).modCount += 1; - } - unseen.remove(curKey); - } - ; - final int resultStorageSize = this.storageRef.size(); - result = startStorageSize != resultStorageSize; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_ValuesAutomaton::removeIf(HashMap_Values, Predicate) -> boolean - * Source: java/util/HashMap.Values.lsl:431 - */ - public boolean removeIf(Predicate filter) { - boolean result = false; - /* body */ { - if (filter == null) { - throw new NullPointerException(); - } - result = false; - final int startStorageSize = this.storageRef.size(); - if (startStorageSize != 0) { - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < startStorageSize; i += 1) { - final Object curKey = unseen.anyKey(); - final Map.Entry entry = unseen.get(curKey); - final Object curValue = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - if (filter.test(curValue)) { - this.storageRef.remove(curKey); - ((HashMap) ((Object) this.parent)).modCount += 1; - } - unseen.remove(curKey); - } - ; - final int resultStorageSize = this.storageRef.size(); - result = startStorageSize != resultStorageSize; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_ValuesAutomaton::retainAll(HashMap_Values, Collection) -> boolean - * Source: java/util/HashMap.Values.lsl:469 - */ - public boolean retainAll(Collection c) { - boolean result = false; - /* body */ { - if (c == null) { - throw new NullPointerException(); - } - result = false; - final int startStorageSize = this.storageRef.size(); - final int cSize = c.size(); - if ((startStorageSize != 0) && (cSize != 0)) { - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < startStorageSize; i += 1) { - final Object curKey = unseen.anyKey(); - final Map.Entry entry = unseen.get(curKey); - final Object curValue = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - if (!c.contains(curValue)) { - this.storageRef.remove(curKey); - ((HashMap) ((Object) this.parent)).modCount += 1; - } - unseen.remove(curKey); - } - ; - final int resultStorageSize = this.storageRef.size(); - result = startStorageSize != resultStorageSize; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_ValuesAutomaton::size(HashMap_Values) -> int - * Source: java/util/HashMap.Values.lsl:507 - */ - public final int size() { - int result = 0; - /* body */ { - result = this.storageRef.size(); - } - return result; - } - - /** - * [FUNCTION] HashMap_ValuesAutomaton::spliterator(HashMap_Values) -> Spliterator - * Source: java/util/HashMap.Values.lsl:513 - */ - public final Spliterator spliterator() { - Spliterator result = null; - /* body */ { - result = (stub.java.util.HashMap_ValueSpliterator) ((Object) new HashMap_ValueSpliterator((Void) null, - /* state = */ HashMap_ValueSpliterator.__$lsl_States.Initialized, - /* valuesStorage = */ _mapToValuesArray(), - /* parent = */ this.parent, - /* index = */ 0, - /* fence = */ -1, - /* est = */ 0, - /* expectedModCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] HashMap_ValuesAutomaton::stream(HashMap_Values) -> Stream - * Source: java/util/HashMap.Values.lsl:523 - */ - public Stream stream() { - Stream result = null; - /* body */ { - final Object[] items = _mapToValuesArray(); - result = (StreamLSL) ((Object) new generated.java.util.stream.StreamLSL((Void) null, - /* state = */ generated.java.util.stream.StreamLSL.__$lsl_States.Initialized, - /* storage = */ items, - /* length = */ items.length, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] HashMap_ValuesAutomaton::toArray(HashMap_Values) -> array - * Source: java/util/HashMap.Values.lsl:536 - */ - public Object[] toArray() { - Object[] result = null; - /* body */ { - final int len = this.storageRef.size(); - result = new Object[len]; - if (len != 0) { - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < len; i += 1) { - final Object key = unseen.anyKey(); - final Map.Entry entry = unseen.get(key); - result[i] = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - unseen.remove(key); - } - ; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_ValuesAutomaton::toArray(HashMap_Values, IntFunction) -> array - * Source: java/util/HashMap.Values.lsl:565 - */ - public Object[] toArray(IntFunction generator) { - Object[] result = null; - /* body */ { - final Object[] a = ((Object[]) generator.apply(0)); - final int aLen = a.length; - final int len = this.storageRef.size(); - result = new Object[len]; - if (len != 0) { - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < len; i += 1) { - final Object key = unseen.anyKey(); - final Map.Entry entry = unseen.get(key); - result[i] = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - unseen.remove(key); - } - ; - } - } - return result; - } - - /** - * [FUNCTION] HashMap_ValuesAutomaton::toArray(HashMap_Values, array) -> array - * Source: java/util/HashMap.Values.lsl:587 - */ - public Object[] toArray(Object[] a) { - Object[] result = null; - /* body */ { - final int aLen = a.length; - final int len = this.storageRef.size(); - if (aLen < len) { - a = new Object[len]; - } - result = a; - if (len != 0) { - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < len; i += 1) { - final Object key = unseen.anyKey(); - final Map.Entry entry = unseen.get(key); - result[i] = ((AbstractMap_SimpleEntry) ((Object) entry)).value; - unseen.remove(key); - } - ; - if (aLen > len) { - result[len] = null; - } - } - } - return result; - } - - /** - * [FUNCTION] HashMap_ValuesAutomaton::toString(HashMap_Values) -> String - * Source: java/util/HashMap.Values.lsl:613 - */ - public String toString() { - String result = null; - /* body */ { - final int size = this.storageRef.size(); - if (size == 0) { - result = "[]"; - } else { - result = "["; - final int lastIndex = size - 1; - final LibSLRuntime.Map> unseen = this.storageRef.duplicate(); - int i = 0; - for (i = 0; i < size; i += 1) { - final Object key = unseen.anyKey(); - final Map.Entry entry = unseen.get(key); - result = result.concat(LibSLRuntime.toString(((AbstractMap_SimpleEntry) ((Object) entry)).value)); - if (i != lastIndex) { - result = result.concat(", "); - } - unseen.remove(key); - } - ; - result = result.concat("]"); - } - } - return result; - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(HashMap_Values.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/HashSet.java b/approximations/src/main/java/generated/java/util/HashSet.java deleted file mode 100644 index 57bf4777..00000000 --- a/approximations/src/main/java/generated/java/util/HashSet.java +++ /dev/null @@ -1,759 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashSet.lsl:20 -// - java/util/HashSet.main.lsl:25 -// -package generated.java.util; - -import generated.runtime.LibSLGlobals; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.lang.Cloneable; -import java.lang.IllegalArgumentException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Collection; -import java.util.ConcurrentModificationException; -import java.util.Iterator; -import java.util.Set; -import java.util.Spliterator; -import java.util.function.Consumer; -import java.util.function.IntFunction; -import java.util.function.Predicate; -import java.util.stream.Stream; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; -import stub.java.util.stream.StreamLSL; - -/** - * HashSetAutomaton for HashSet ~> java.util.HashSet - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.util.HashSet.class) -public class HashSet implements LibSLRuntime.Automaton, Set, Cloneable, Serializable { - private static final long serialVersionUID = -5024744406713321676L; - - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public LibSLRuntime.Map storage; - - public transient int modCount; - - @LibSLRuntime.AutomatonConstructor - public HashSet(Void __$lsl_token, final byte p0, final LibSLRuntime.Map p1, - final int p2) { - this.__$lsl_state = p0; - this.storage = p1; - this.modCount = p2; - } - - @LibSLRuntime.AutomatonConstructor - public HashSet(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, null, 0); - } - - /** - * [CONSTRUCTOR] HashSetAutomaton::(HashSet) -> void - * Source: java/util/HashSet.main.lsl:157 - */ - public HashSet() { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.storage = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] HashSetAutomaton::(HashSet, Collection) -> void - * Source: java/util/HashSet.main.lsl:163 - */ - public HashSet(Collection c) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.storage = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - _addAllElements(c); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] HashSetAutomaton::(HashSet, int) -> void - * Source: java/util/HashSet.main.lsl:170 - */ - public HashSet(int initialCapacity) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - if (initialCapacity < 0) { - throw new IllegalArgumentException(); - } - this.storage = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] HashSetAutomaton::(HashSet, int, float) -> void - * Source: java/util/HashSet.main.lsl:182 - */ - public HashSet(int initialCapacity, float loadFactor) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - if (initialCapacity < 0) { - throw new IllegalArgumentException(); - } - if ((loadFactor <= 0) || (loadFactor != loadFactor)) { - throw new IllegalArgumentException(); - } - this.storage = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] HashSetAutomaton::(HashSet, int, float, boolean) -> void - * Source: java/util/HashSet.main.lsl:200 - */ - private HashSet(int initialCapacity, float loadFactor, boolean dummy) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - LibSLRuntime.error("Private constructor call"); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] HashSetAutomaton::_checkForComodification(int) -> void - * Source: java/util/HashSet.main.lsl:79 - */ - public void _checkForComodification(int expectedModCount) { - /* body */ { - if (this.modCount != expectedModCount) { - throw new ConcurrentModificationException(); - } - } - } - - /** - * [SUBROUTINE] HashSetAutomaton::_addAllElements(Collection) -> boolean - * Source: java/util/HashSet.main.lsl:86 - */ - private boolean _addAllElements(Collection c) { - boolean result = false; - /* body */ { - final int lengthBeforeAdd = this.storage.size(); - final Iterator iter = c.iterator(); - while (iter.hasNext()) { - final Object key = iter.next(); - if (!this.storage.hasKey(key)) { - this.storage.set(key, LibSLGlobals.SOMETHING); - } - } - ; - if (lengthBeforeAdd != this.storage.size()) { - this.modCount += 1; - result = true; - } else { - result = false; - } - } - return result; - } - - /** - * [SUBROUTINE] HashSetAutomaton::_makeStream(boolean) -> Stream - * Source: java/util/HashSet.main.lsl:123 - */ - private Stream _makeStream(boolean parallel) { - Stream result = null; - /* body */ { - final LibSLRuntime.Map unseen = this.storage.duplicate(); - final int count = unseen.size(); - final Object[] items = new Object[count]; - int i = 0; - for (i = 0; i < count; i += 1) { - final Object key = unseen.anyKey(); - unseen.remove(key); - items[i] = key; - } - ; - result = (StreamLSL) ((Object) new generated.java.util.stream.StreamLSL((Void) null, - /* state = */ generated.java.util.stream.StreamLSL.__$lsl_States.Initialized, - /* storage = */ items, - /* length = */ count, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ parallel, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] HashSetAutomaton::add(HashSet, Object) -> boolean - * Source: java/util/HashSet.main.lsl:208 - */ - public boolean add(Object obj) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final boolean hasKey = this.storage.hasKey(obj); - if (hasKey) { - result = false; - } else { - this.storage.set(obj, LibSLGlobals.SOMETHING); - result = true; - } - this.modCount += 1; - } - return result; - } - - /** - * [FUNCTION] HashSetAutomaton::clear(HashSet) -> void - * Source: java/util/HashSet.main.lsl:226 - */ - public void clear() { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.storage = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - this.modCount += 1; - } - } - - /** - * [FUNCTION] HashSetAutomaton::clone(HashSet) -> Object - * Source: java/util/HashSet.main.lsl:233 - */ - public Object clone() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (java.util.HashSet) ((Object) new HashSet((Void) null, - /* state = */ HashSet.__$lsl_States.Initialized, - /* storage = */ this.storage.duplicate(), - /* modCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] HashSetAutomaton::contains(HashSet, Object) -> boolean - * Source: java/util/HashSet.main.lsl:241 - */ - public boolean contains(Object obj) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.storage.size() == 0) { - result = false; - } else { - result = this.storage.hasKey(obj); - } - } - return result; - } - - /** - * [FUNCTION] HashSetAutomaton::isEmpty(HashSet) -> boolean - * Source: java/util/HashSet.main.lsl:250 - */ - public boolean isEmpty() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.storage.size() == 0; - } - return result; - } - - /** - * [FUNCTION] HashSetAutomaton::iterator(HashSet) -> Iterator - * Source: java/util/HashSet.main.lsl:256 - */ - public Iterator iterator() { - Iterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final LibSLRuntime.Map unseenKeys = this.storage.duplicate(); - result = (stub.java.util.HashSet_KeyIterator) ((Object) new HashSet_KeyIterator((Void) null, - /* state = */ HashSet_KeyIterator.__$lsl_States.Initialized, - /* expectedModCount = */ this.modCount, - /* unseenKeys = */ unseenKeys, - /* parent = */ this, - /* index = */ 0, - /* currentKey = */ 0, - /* nextWasCalled = */ false - )); - } - return result; - } - - /** - * [FUNCTION] HashSetAutomaton::remove(HashSet, Object) -> boolean - * Source: java/util/HashSet.main.lsl:267 - */ - public boolean remove(Object obj) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.storage.hasKey(obj)) { - this.storage.remove(obj); - this.modCount += 1; - result = true; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] HashSetAutomaton::size(HashSet) -> int - * Source: java/util/HashSet.main.lsl:282 - */ - public int size() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.storage.size(); - } - return result; - } - - /** - * [FUNCTION] HashSetAutomaton::spliterator(HashSet) -> Spliterator - * Source: java/util/HashSet.main.lsl:288 - */ - public Spliterator spliterator() { - Spliterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final Object[] keysStorageArray = new Object[this.storage.size()]; - final LibSLRuntime.Map unseenKeys = this.storage.duplicate(); - int i = 0; - for (i = 0; i < this.storage.size(); i += 1) { - final Object key = unseenKeys.anyKey(); - unseenKeys.remove(key); - keysStorageArray[i] = key; - } - ; - result = (stub.java.util.HashSet_KeySpliterator) ((Object) new HashSet_KeySpliterator((Void) null, - /* state = */ HashSet_KeySpliterator.__$lsl_States.Initialized, - /* keysStorage = */ keysStorageArray, - /* index = */ 0, - /* fence = */ -1, - /* est = */ 0, - /* expectedModCount = */ this.modCount, - /* parent = */ this - )); - } - return result; - } - - /** - * [FUNCTION] HashSetAutomaton::equals(HashSet, Object) -> boolean - * Source: java/util/HashSet.main.lsl:320 - */ - public boolean equals(Object other) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (other == this) { - result = true; - } else { - if ((other != null && other.getClass() == java.util.HashSet.class)) { - final int expectedModCount = this.modCount; - final int otherExpectedModCount = ((HashSet) ((Object) other)).modCount; - final LibSLRuntime.Map otherStorage = ((HashSet) ((Object) other)).storage; - if (this.storage.size() == otherStorage.size()) { - result = LibSLRuntime.equals(this.storage, otherStorage); - } else { - result = false; - } - ((HashSet) ((Object) other))._checkForComodification(otherExpectedModCount); - _checkForComodification(expectedModCount); - } else { - result = false; - } - } - } - return result; - } - - /** - * [FUNCTION] HashSetAutomaton::hashCode(HashSet) -> int - * Source: java/util/HashSet.main.lsl:351 - */ - public int hashCode() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = LibSLRuntime.hashCode(this.storage); - } - return result; - } - - /** - * [FUNCTION] HashSetAutomaton::removeAll(HashSet, Collection) -> boolean - * Source: java/util/HashSet.main.lsl:357 - */ - public boolean removeAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (c == null) { - throw new NullPointerException(); - } - final int expectedModCount = this.modCount; - final int otherSize = c.size(); - final Iterator iter = c.iterator(); - final int lengthBeforeRemoving = this.storage.size(); - int i = 0; - if (this.storage.size() > otherSize) { - while (iter.hasNext()) { - final Object key = iter.next(); - if (this.storage.hasKey(key)) { - this.storage.remove(key); - } - } - ; - } else { - final LibSLRuntime.Map unseenKeys = this.storage.duplicate(); - while (i < lengthBeforeRemoving) { - final Object key = unseenKeys.anyKey(); - unseenKeys.remove(key); - if (c.contains(key)) { - this.storage.remove(key); - } - i += 1; - } - ; - } - _checkForComodification(expectedModCount); - this.modCount += 1; - result = lengthBeforeRemoving != this.storage.size(); - } - return result; - } - - /** - * [FUNCTION] HashSetAutomaton::toArray(HashSet) -> array - * Source: java/util/HashSet.main.lsl:413 - */ - public Object[] toArray() { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int len = this.storage.size(); - result = new Object[len]; - final int expectedModCount = this.modCount; - final LibSLRuntime.Map unseenKeys = this.storage.duplicate(); - int i = 0; - for (i = 0; i < len; i += 1) { - final Object key = unseenKeys.anyKey(); - unseenKeys.remove(key); - result[i] = key; - } - ; - _checkForComodification(expectedModCount); - } - return result; - } - - /** - * [FUNCTION] HashSetAutomaton::toArray(HashSet, array) -> array - * Source: java/util/HashSet.main.lsl:439 - */ - public Object[] toArray(Object[] a) { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int expectedModCount = this.modCount; - final int aLen = a.length; - final int len = this.storage.size(); - final LibSLRuntime.Map unseenKeys = this.storage.duplicate(); - int i = 0; - if (aLen < len) { - a = new Object[len]; - } - result = a; - for (i = 0; i < len; i += 1) { - final Object key = unseenKeys.anyKey(); - unseenKeys.remove(key); - result[i] = key; - } - ; - if (aLen > len) { - result[len] = null; - } - _checkForComodification(expectedModCount); - } - return result; - } - - /** - * [FUNCTION] HashSetAutomaton::toArray(HashSet, IntFunction) -> array - * Source: java/util/HashSet.main.lsl:464 - */ - public Object[] toArray(IntFunction generator) { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (generator == null) { - throw new NullPointerException(); - } - final int len = this.storage.size(); - result = ((Object[]) generator.apply(0)); - final int expectedModCount = this.modCount; - final LibSLRuntime.Map unseenKeys = this.storage.duplicate(); - int i = 0; - for (i = 0; i < len; i += 1) { - final Object key = unseenKeys.anyKey(); - unseenKeys.remove(key); - result[i] = key; - } - ; - _checkForComodification(expectedModCount); - } - return result; - } - - /** - * [FUNCTION] HashSetAutomaton::containsAll(HashSet, Collection) -> boolean - * Source: java/util/HashSet.main.lsl:484 - */ - public boolean containsAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int otherSize = c.size(); - final Iterator iter = c.iterator(); - boolean isContainsAll = true; - while (iter.hasNext()) { - final Object key = iter.next(); - final boolean isKeyExist = this.storage.hasKey(key); - if (!isKeyExist) { - isContainsAll = false; - break; - } - } - ; - result = isContainsAll; - } - return result; - } - - /** - * [FUNCTION] HashSetAutomaton::addAll(HashSet, Collection) -> boolean - * Source: java/util/HashSet.main.lsl:512 - */ - public boolean addAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _addAllElements(c); - } - return result; - } - - /** - * [FUNCTION] HashSetAutomaton::retainAll(HashSet, Collection) -> boolean - * Source: java/util/HashSet.main.lsl:518 - */ - public boolean retainAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (c == null) { - throw new NullPointerException(); - } - final int lengthBeforeAdd = this.storage.size(); - final LibSLRuntime.Map unseenKeys = this.storage.duplicate(); - int i = 0; - while (i < lengthBeforeAdd) { - final Object key = unseenKeys.anyKey(); - unseenKeys.remove(key); - if (!c.contains(key)) { - this.storage.remove(key); - } - i += 1; - } - ; - if (lengthBeforeAdd != this.storage.size()) { - this.modCount += 1; - result = true; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] HashSetAutomaton::removeIf(HashSet, Predicate) -> boolean - * Source: java/util/HashSet.main.lsl:556 - */ - public boolean removeIf(Predicate filter) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (filter == null) { - throw new NullPointerException(); - } - final int lengthBeforeAdd = this.storage.size(); - final int expectedModCount = this.modCount; - int i = 0; - final LibSLRuntime.Map unseenKeys = this.storage.duplicate(); - while (i < lengthBeforeAdd) { - final Object key = unseenKeys.anyKey(); - unseenKeys.remove(key); - if (filter.test(key)) { - this.storage.remove(key); - } - i += 1; - } - ; - _checkForComodification(expectedModCount); - if (lengthBeforeAdd != this.storage.size()) { - this.modCount += 1; - result = true; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] HashSetAutomaton::forEach(HashSet, Consumer) -> void - * Source: java/util/HashSet.main.lsl:596 - */ - public void forEach(Consumer userAction) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (userAction == null) { - throw new NullPointerException(); - } - int i = 0; - final int count = this.storage.size(); - final int expectedModCount = this.modCount; - final LibSLRuntime.Map unseenKeys = this.storage.duplicate(); - while (i < count) { - final Object key = unseenKeys.anyKey(); - unseenKeys.remove(key); - userAction.accept(key); - i += 1; - } - ; - _checkForComodification(expectedModCount); - } - } - - /** - * [FUNCTION] HashSetAutomaton::stream(HashSet) -> Stream - * Source: java/util/HashSet.main.lsl:627 - */ - public Stream stream() { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _makeStream(false); - } - return result; - } - - /** - * [FUNCTION] HashSetAutomaton::parallelStream(HashSet) -> Stream - * Source: java/util/HashSet.main.lsl:634 - */ - public Stream parallelStream() { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _makeStream(true); - } - return result; - } - - /** - * [FUNCTION] HashSetAutomaton::writeObject(HashSet, ObjectOutputStream) -> void - * Source: java/util/HashSet.main.lsl:642 - */ - private void writeObject(ObjectOutputStream s) throws java.io.IOException { - /* body */ { - LibSLRuntime.not_implemented(/* no serialization support yet */); - } - } - - /** - * [FUNCTION] HashSetAutomaton::readObject(HashSet, ObjectInputStream) -> void - * Source: java/util/HashSet.main.lsl:649 - */ - private void readObject(ObjectInputStream s) throws java.io.IOException, - java.lang.ClassNotFoundException { - /* body */ { - LibSLRuntime.not_implemented(/* no serialization support yet */); - } - } - - /** - * [FUNCTION] HashSetAutomaton::toString(HashSet) -> String - * Source: java/util/HashSet.main.lsl:657 - */ - public String toString() { - String result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final LibSLRuntime.Map items = this.storage; - int count = items.size(); - if (count == 0) { - result = "[]"; - } else { - Engine.assume(count > 0); - result = "["; - final LibSLRuntime.Map unseen = items.duplicate(); - while (count != 0) { - final Object key = unseen.anyKey(); - unseen.remove(key); - result = result.concat(LibSLRuntime.toString(key)); - if (count > 1) { - result = result.concat(", "); - } - count -= 1; - } - ; - result = result.concat("]"); - } - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(HashSet.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/HashSet_KeyIterator.java b/approximations/src/main/java/generated/java/util/HashSet_KeyIterator.java deleted file mode 100644 index e6f762f4..00000000 --- a/approximations/src/main/java/generated/java/util/HashSet_KeyIterator.java +++ /dev/null @@ -1,193 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashSet.lsl:41 -// - java/util/HashSet.KeyIterator.lsl:19 -// -package generated.java.util; - -import java.lang.IllegalStateException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ConcurrentModificationException; -import java.util.Iterator; -import java.util.NoSuchElementException; -import java.util.function.Consumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * HashSet_KeyIteratorAutomaton for HashSet_KeyIterator ~> java.util.HashSet_KeyIterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.HashSet_KeyIterator.class) -public final class HashSet_KeyIterator implements LibSLRuntime.Automaton, Iterator { - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public int expectedModCount; - - public LibSLRuntime.Map unseenKeys; - - public HashSet parent; - - public int index; - - public Object currentKey; - - public boolean nextWasCalled; - - @LibSLRuntime.AutomatonConstructor - public HashSet_KeyIterator(Void __$lsl_token, final byte p0, final int p1, - final LibSLRuntime.Map p2, final HashSet p3, final int p4, - final Object p5, final boolean p6) { - this.__$lsl_state = p0; - this.expectedModCount = p1; - this.unseenKeys = p2; - this.parent = p3; - this.index = p4; - this.currentKey = p5; - this.nextWasCalled = p6; - } - - @LibSLRuntime.AutomatonConstructor - public HashSet_KeyIterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, 0, null, null, 0, 0, false); - } - - /** - * [CONSTRUCTOR] HashSet_KeyIteratorAutomaton::(HashSet_KeyIterator, HashMap) -> void - * Source: java/util/HashSet.KeyIterator.lsl:66 - */ - private HashSet_KeyIterator(HashMap source) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - LibSLRuntime.error("Private constructor call"); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] HashSet_KeyIteratorAutomaton::_checkForComodification() -> void - * Source: java/util/HashSet.KeyIterator.lsl:56 - */ - private void _checkForComodification() { - /* body */ { - final int modCount = ((HashSet) ((Object) this.parent)).modCount; - if (this.expectedModCount != modCount) { - throw new ConcurrentModificationException(); - } - } - } - - /** - * [FUNCTION] HashSet_KeyIteratorAutomaton::hasNext(HashSet_KeyIterator) -> boolean - * Source: java/util/HashSet.KeyIterator.lsl:74 - */ - public boolean hasNext() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.parent != null); - final LibSLRuntime.Map parentStorage = ((HashSet) ((Object) this.parent)).storage; - final int length = parentStorage.size(); - result = this.index < length; - } - return result; - } - - /** - * [FUNCTION] HashSet_KeyIteratorAutomaton::next(HashSet_KeyIterator) -> Object - * Source: java/util/HashSet.KeyIterator.lsl:84 - */ - public final Object next() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.parent != null); - _checkForComodification(); - final LibSLRuntime.Map parentStorage = ((HashSet) ((Object) this.parent)).storage; - final int length = parentStorage.size(); - final boolean atValidPosition = this.index < length; - if (!atValidPosition) { - throw new NoSuchElementException(); - } - final Object key = this.unseenKeys.anyKey(); - this.unseenKeys.remove(key); - this.currentKey = key; - result = key; - this.index += 1; - this.nextWasCalled = true; - } - return result; - } - - /** - * [FUNCTION] HashSet_KeyIteratorAutomaton::remove(HashSet_KeyIterator) -> void - * Source: java/util/HashSet.KeyIterator.lsl:106 - */ - public void remove() { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.parent != null); - final LibSLRuntime.Map parentStorage = ((HashSet) ((Object) this.parent)).storage; - final int length = parentStorage.size(); - final boolean atValidPosition = this.index < length; - if (!atValidPosition || !this.nextWasCalled) { - throw new IllegalStateException(); - } - this.nextWasCalled = false; - _checkForComodification(); - parentStorage.remove(this.currentKey); - this.expectedModCount = ((HashSet) ((Object) this.parent)).modCount; - } - } - - /** - * [FUNCTION] HashSet_KeyIteratorAutomaton::forEachRemaining(HashSet_KeyIterator, Consumer) -> void - * Source: java/util/HashSet.KeyIterator.lsl:126 - */ - public void forEachRemaining(Consumer userAction) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.parent != null); - if (userAction == null) { - throw new NullPointerException(); - } - final LibSLRuntime.Map parentStorage = ((HashSet) ((Object) this.parent)).storage; - final int length = parentStorage.size(); - int i = this.index; - while (i < length) { - _checkForComodification(); - final Object key = this.unseenKeys.anyKey(); - this.unseenKeys.remove(key); - Engine.assume(key != this.currentKey); - this.currentKey = key; - userAction.accept(key); - i += 1; - } - ; - this.index = i; - this.nextWasCalled = true; - } - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(HashSet_KeyIterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/HashSet_KeySpliterator.java b/approximations/src/main/java/generated/java/util/HashSet_KeySpliterator.java deleted file mode 100644 index ea7cc2ba..00000000 --- a/approximations/src/main/java/generated/java/util/HashSet_KeySpliterator.java +++ /dev/null @@ -1,255 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashSet.lsl:32 -// - java/util/HashSet.Spliterator.lsl:19 -// -package generated.java.util; - -import generated.runtime.LibSLGlobals; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ConcurrentModificationException; -import java.util.Spliterator; -import java.util.function.Consumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * HashSet_KeySpliteratorAutomaton for HashSet_KeySpliterator ~> java.util.HashSet_KeySpliterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.HashSet_KeySpliterator.class) -public final class HashSet_KeySpliterator implements LibSLRuntime.Automaton, Spliterator { - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public Object[] keysStorage; - - public int index; - - public int fence; - - public int est; - - public int expectedModCount; - - public HashSet parent; - - @LibSLRuntime.AutomatonConstructor - public HashSet_KeySpliterator(Void __$lsl_token, final byte p0, final Object[] p1, final int p2, - final int p3, final int p4, final int p5, final HashSet p6) { - this.__$lsl_state = p0; - this.keysStorage = p1; - this.index = p2; - this.fence = p3; - this.est = p4; - this.expectedModCount = p5; - this.parent = p6; - } - - @LibSLRuntime.AutomatonConstructor - public HashSet_KeySpliterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, null, 0, 0, 0, 0, null); - } - - /** - * [CONSTRUCTOR] HashSet_KeySpliteratorAutomaton::(HashSet_KeySpliterator, HashMap, int, int, int, int) -> void - * Source: java/util/HashSet.Spliterator.lsl:89 - */ - private HashSet_KeySpliterator(HashMap source, int origin, int fence, int est, - int expectedModCount) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.index = origin; - fence = fence; - est = est; - expectedModCount = expectedModCount; - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] HashSet_KeySpliteratorAutomaton::_getFence() -> int - * Source: java/util/HashSet.Spliterator.lsl:54 - */ - private int _getFence() { - int result = 0; - /* body */ { - Engine.assume(this.parent != null); - int hi = this.fence; - if (hi < 0) { - final LibSLRuntime.Map parentStorage = ((HashSet) ((Object) this.parent)).storage; - this.est = parentStorage.size(); - this.expectedModCount = ((HashSet) ((Object) this.parent)).modCount; - this.fence = this.est; - hi = this.fence; - } - result = hi; - } - return result; - } - - /** - * [SUBROUTINE] HashSet_KeySpliteratorAutomaton::_checkForComodification() -> void - * Source: java/util/HashSet.Spliterator.lsl:79 - */ - private void _checkForComodification() { - /* body */ { - final int modCount = ((HashSet) ((Object) this.parent)).modCount; - if (this.expectedModCount != modCount) { - throw new ConcurrentModificationException(); - } - } - } - - /** - * [FUNCTION] HashSet_KeySpliteratorAutomaton::estimateSize(HashSet_KeySpliterator) -> long - * Source: java/util/HashSet.Spliterator.lsl:101 - */ - public long estimateSize() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _getFence(); - result = ((long) this.est); - } - return result; - } - - /** - * [FUNCTION] HashSet_KeySpliteratorAutomaton::characteristics(HashSet_KeySpliterator) -> int - * Source: java/util/HashSet.Spliterator.lsl:108 - */ - public int characteristics() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.parent != null); - result = 0; - final LibSLRuntime.Map parentStorage = ((HashSet) ((Object) this.parent)).storage; - final int length = parentStorage.size(); - if ((this.fence < 0) || (this.est == length)) { - result = LibSLGlobals.SPLITERATOR_SIZED; - } - result |= LibSLGlobals.SPLITERATOR_DISTINCT; - } - return result; - } - - /** - * [FUNCTION] HashSet_KeySpliteratorAutomaton::forEachRemaining(HashSet_KeySpliterator, Consumer) -> void - * Source: java/util/HashSet.Spliterator.lsl:122 - */ - public void forEachRemaining(Consumer userAction) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.parent != null); - if (userAction == null) { - throw new NullPointerException(); - } - int hi = this.fence; - int mc = this.expectedModCount; - int i = this.index; - final LibSLRuntime.Map parentStorage = ((HashSet) ((Object) this.parent)).storage; - final int length = parentStorage.size(); - if (hi < 0) { - this.expectedModCount = ((HashSet) ((Object) this.parent)).modCount; - mc = this.expectedModCount; - this.fence = length; - hi = this.fence; - } - this.index = hi; - if ((length > 0) && (length >= hi) && (i >= 0) && (i < this.index)) { - final Object[] storage = this.keysStorage; - Engine.assume(storage != null); - while (i < hi) { - final Object key = storage[i]; - userAction.accept(key); - i += 1; - } - ; - final int modCount = ((HashSet) ((Object) this.parent)).modCount; - if (modCount != mc) { - throw new ConcurrentModificationException(); - } - } - } - } - - /** - * [FUNCTION] HashSet_KeySpliteratorAutomaton::tryAdvance(HashSet_KeySpliterator, Consumer) -> boolean - * Source: java/util/HashSet.Spliterator.lsl:173 - */ - public boolean tryAdvance(Consumer userAction) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.parent != null); - if (userAction == null) { - throw new NullPointerException(); - } - int hi = _getFence(); - int i = this.index; - if (i < hi) { - final Object key = keysStorage[i]; - userAction.accept(key); - this.index += 1; - _checkForComodification(); - result = true; - } - result = false; - } - return result; - } - - /** - * [FUNCTION] HashSet_KeySpliteratorAutomaton::trySplit(HashSet_KeySpliterator) -> Spliterator - * Source: java/util/HashSet.Spliterator.lsl:197 - */ - public Spliterator trySplit() { - Spliterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.parent != null); - final int hi = _getFence(); - final int lo = this.index; - int mid = (hi + lo) >>> 1; - if (lo >= mid) { - result = null; - } else { - this.est = this.est >>> 1; - this.index = mid; - result = (stub.java.util.HashSet_KeySpliterator) ((Object) new HashSet_KeySpliterator((Void) null, - /* state = */ HashSet_KeySpliterator.__$lsl_States.Initialized, - /* keysStorage = */ this.keysStorage, - /* index = */ lo, - /* fence = */ mid, - /* est = */ this.est, - /* expectedModCount = */ this.expectedModCount, - /* parent = */ this.parent - )); - } - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(HashSet_KeySpliterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/HeapByteBufferImpl.java b/approximations/src/main/java/generated/java/util/HeapByteBufferImpl.java new file mode 100644 index 00000000..43ba0da9 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/HeapByteBufferImpl.java @@ -0,0 +1,248 @@ +package generated.java.util; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +import java.nio.*; + +@Approximate(stub.java.util.HeapByteBuffer.class) +public class HeapByteBufferImpl extends ByteBufferImpl { + HeapByteBufferImpl(int cap, int lim) { + super(-1, 0, lim, cap, new byte[cap], 0); + } + + HeapByteBufferImpl(byte[] buf, int off, int len) { + super(-1, off, off + len, buf.length, buf, 0); + } + + protected HeapByteBufferImpl(byte[] buf, int mark, int pos, int lim, int cap, int off) { + super(mark, pos, lim, cap, buf, off); + } + + public ByteBufferImpl slice() { + int pos = this.position(); + int lim = this.limit(); + int rem = (pos <= lim ? lim - pos : 0); + return new HeapByteBufferImpl(storage, -1, 0, rem, rem, pos + offset); + } + + @Override + public ByteBufferImpl slice(int index, int length) { + checkFromIndexSize(index, length, limit()); + return new HeapByteBufferImpl(storage, -1, 0, length, length, index + offset); + } + + public ByteBufferImpl duplicate() { + return new HeapByteBufferImpl(storage, this.markValue(), this.position(), this.limit(), this.capacity(), + offset); + } + + public ByteBufferImpl asReadOnlyBuffer() { + return new HeapByteBufferRImpl(storage, this.markValue(), this.position(), this.limit(), this.capacity(), + offset); + } + + public byte get() { + return super.get(); + } + + public byte get(int i) { + return super.get(i); + } + + public ByteBufferImpl get(byte[] dst, int offset, int length) { + checkFromIndexSize(offset, length, dst.length); + int pos = position(); + if (length > limit() - pos) + throw new BufferUnderflowException(); + int indexWithOffset = applyOffset(pos); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(storage, applyOffset(pos), dst, offset, length); + position(pos + length); + return this; + } + + public ByteBufferImpl get(int index, byte[] dst, int offset, int length) { + return super.get(index, dst, offset, length); + } + + public boolean isDirect() { + return false; + } + + public boolean isReadOnly() { + return false; + } + + public ByteBufferImpl put(byte x) { + return super.put(x); + } + + public ByteBufferImpl put(int i, byte x) { + return super.put(i, x); + } + + public ByteBufferImpl put(byte[] src, int offset, int length) { + checkFromIndexSize(offset, length, src.length); + int pos = position(); + if (length > limit() - pos) + throw new BufferOverflowException(); + int indexWithOffset = applyOffset(pos); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(src, offset, storage, indexWithOffset, length); + position(pos + length); + return this; + } + + public ByteBufferImpl put(ByteBufferImpl src) { + super.put(src); + return this; + } + + public ByteBufferImpl put(int index, ByteBufferImpl src, int offset, int length) { + super.put(index, src, offset, length); + return this; + } + + public ByteBufferImpl put(int index, byte[] src, int offset, int length) { + checkFromIndexSize(index, length, limit()); + checkFromIndexSize(offset, length, src.length); + int indexWithOffset = applyOffset(index); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(src, offset, storage, applyOffset(index), length); + return this; + } + + public ByteBufferImpl compact() { + return super.compact(); + } + + byte _get(int i) { + return storage[i]; + } + + void _put(int i, byte b) { + storage[i] = b; + } + + public char getChar() { + return super.getChar(); + } + + public char getChar(int i) { + return super.getChar(i); + } + + public ByteBufferImpl putChar(char x) { + return super.putChar(x); + } + + public ByteBufferImpl putChar(int i, char x) { + return super.putChar(i, x); + } + + public CharBuffer asCharBuffer() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public short getShort() { + return super.getShort(); + } + + public short getShort(int i) { + return super.getShort(i); + } + + public ByteBufferImpl putShort(short x) { + return super.putShort(x); + } + + public ByteBufferImpl putShort(int i, short x) { + return super.putShort(i, x); + } + + public ShortBuffer asShortBuffer() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public int getInt() { + return super.getInt(); + } + + public int getInt(int i) { + return super.getInt(i); + } + + public ByteBufferImpl putInt(int x) { + return super.putInt(x); + } + + public ByteBufferImpl putInt(int i, int x) { + return super.putInt(i, x); + } + + public IntBuffer asIntBuffer() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public long getLong() { + return super.getLong(); + } + + public long getLong(int i) { + return super.getLong(i); + } + + public ByteBufferImpl putLong(long x) { + return super.putLong(x); + } + + public ByteBufferImpl putLong(int i, long x) { + return super.putLong(i, x); + } + + public LongBuffer asLongBuffer() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public float getFloat() { + return super.getFloat(); + } + + public float getFloat(int i) { + return super.getFloat(i); + } + + public ByteBufferImpl putFloat(float x) { + return super.putFloat(x); + } + + public ByteBufferImpl putFloat(int i, float x) { + return super.putFloat(i, x); + } + + public FloatBuffer asFloatBuffer() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public double getDouble() { + return super.getDouble(); + } + + public double getDouble(int i) { + return super.getDouble(i); + } + + public ByteBufferImpl putDouble(double x) { + return super.putDouble(x); + } + + public ByteBufferImpl putDouble(int i, double x) { + return super.putDouble(i, x); + } + + public DoubleBuffer asDoubleBuffer() { + throw new UnsupportedOperationException("Not implemented yet"); + } +} diff --git a/approximations/src/main/java/generated/java/util/HeapByteBufferRImpl.java b/approximations/src/main/java/generated/java/util/HeapByteBufferRImpl.java new file mode 100644 index 00000000..01bb6609 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/HeapByteBufferRImpl.java @@ -0,0 +1,155 @@ +package generated.java.util; + +import jdk.internal.access.foreign.MemorySegmentProxy; +import org.jacodb.approximation.annotation.Approximate; + +import java.nio.*; +import java.util.Objects; + +@Approximate(stub.java.util.HeapByteBufferR.class) +public class HeapByteBufferRImpl extends HeapByteBufferImpl { + HeapByteBufferRImpl(int cap, int lim) { + super(cap, lim); + this.isReadOnly = true; + } + + HeapByteBufferRImpl(byte[] buf, int off, int len) { + super(buf, off, len); + this.isReadOnly = true; + } + + protected HeapByteBufferRImpl(byte[] buf, int mark, int pos, int lim, int cap, int off) { + super(buf, mark, pos, lim, cap, off); + this.isReadOnly = true; + } + + public ByteBufferImpl slice() { + int pos = this.position(); + int lim = this.limit(); + int rem = (pos <= lim ? lim - pos : 0); + return new HeapByteBufferRImpl(storage, -1, 0, rem, rem, pos + offset); + } + + @Override + public ByteBufferImpl slice(int index, int length) { + checkFromIndexSize(index, length, limit()); + return new HeapByteBufferRImpl(storage, -1, 0, length, length, index + offset); + } + + public ByteBufferImpl duplicate() { + return new HeapByteBufferRImpl(storage, this.markValue(), this.position(), this.limit(), this.capacity(), + offset); + } + + public ByteBufferImpl asReadOnlyBuffer() { + return duplicate(); + } + + public boolean isReadOnly() { + return true; + } + + public ByteBufferImpl put(byte x) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl put(int i, byte x) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl put(byte[] src, int offset, int length) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl put(ByteBufferImpl src) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl put(int index, ByteBufferImpl src, int offset, int length) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl put(int index, byte[] src, int offset, int length) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl compact() { + throw new ReadOnlyBufferException(); + } + + void _put(int i, byte b) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl putChar(char x) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl putChar(int i, char x) { + throw new ReadOnlyBufferException(); + } + + public CharBuffer asCharBuffer() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public ByteBufferImpl putShort(short x) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl putShort(int i, short x) { + throw new ReadOnlyBufferException(); + } + + public ShortBuffer asShortBuffer() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public ByteBufferImpl putInt(int x) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl putInt(int i, int x) { + throw new ReadOnlyBufferException(); + } + + public IntBuffer asIntBuffer() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public ByteBufferImpl putLong(long x) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl putLong(int i, long x) { + throw new ReadOnlyBufferException(); + } + + public LongBuffer asLongBuffer() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public ByteBufferImpl putFloat(float x) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl putFloat(int i, float x) { + throw new ReadOnlyBufferException(); + } + + public FloatBuffer asFloatBuffer() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public ByteBufferImpl putDouble(double x) { + throw new ReadOnlyBufferException(); + } + + public ByteBufferImpl putDouble(int i, double x) { + throw new ReadOnlyBufferException(); + } + + public DoubleBuffer asDoubleBuffer() { + throw new UnsupportedOperationException("Not implemented yet"); + } +} diff --git a/approximations/src/main/java/generated/java/util/HeapCharBufferImpl.java b/approximations/src/main/java/generated/java/util/HeapCharBufferImpl.java new file mode 100644 index 00000000..4be8cdd6 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/HeapCharBufferImpl.java @@ -0,0 +1,144 @@ +package generated.java.util; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +import java.nio.*; + +@Approximate(stub.java.util.HeapCharBuffer.class) +public class HeapCharBufferImpl extends CharBufferImpl { + HeapCharBufferImpl(int cap, int lim) { + super(-1, 0, lim, cap, new char[cap], 0); + } + + HeapCharBufferImpl(char[] buf, int off, int len) { + super(-1, off, off + len, buf.length, buf, 0); + } + + protected HeapCharBufferImpl(char[] buf, int mark, int pos, int lim, int cap, int off) { + super(mark, pos, lim, cap, buf, off); + } + + public CharBufferImpl slice() { + int pos = this.position(); + int lim = this.limit(); + int rem = (pos <= lim ? lim - pos : 0); + return new HeapCharBufferImpl(storage, -1, 0, rem, rem, pos + offset); + } + + @Override + public CharBufferImpl slice(int index, int length) { + checkFromIndexSize(index, length, limit()); + return new HeapCharBufferImpl(storage, -1, 0, length, length, index + offset); + } + + public CharBufferImpl duplicate() { + return new HeapCharBufferImpl(storage, this.markValue(), this.position(), this.limit(), this.capacity(), offset); + } + + public CharBufferImpl asReadOnlyBuffer() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public char get() { + return super.get(); + } + + public char get(int i) { + return super.get(i); + } + + char getUnchecked(int i) { + return super.getUnchecked(i); + } + + public CharBufferImpl get(char[] dst, int offset, int length) { + checkFromIndexSize(offset, length, dst.length); + int pos = position(); + if (length > limit() - pos) + throw new BufferUnderflowException(); + int indexWithOffset = applyOffset(pos); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(storage, applyOffset(pos), dst, offset, length); + position(pos + length); + return this; + } + + public CharBufferImpl get(int index, char[] dst, int offset, int length) { + return super.get(index, dst, offset, length); + } + + public boolean isDirect() { + return false; + } + + public boolean isReadOnly() { + return false; + } + + public CharBufferImpl put(char x) { + return super.put(x); + } + + public CharBufferImpl put(int i, char x) { + return super.put(i, x); + } + + public CharBufferImpl put(char[] src, int offset, int length) { + checkFromIndexSize(offset, length, src.length); + int pos = position(); + if (length > limit() - pos) + throw new BufferOverflowException(); + int indexWithOffset = applyOffset(pos); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(src, offset, storage, indexWithOffset, length); + position(pos + length); + return this; + } + + public CharBufferImpl put(CharBufferImpl src) { + super.put(src); + return this; + } + + public CharBufferImpl put(int index, CharBufferImpl src, int offset, int length) { + super.put(index, src, offset, length); + return this; + } + + public CharBufferImpl put(int index, char[] src, int offset, int length) { + checkFromIndexSize(index, length, limit()); + checkFromIndexSize(offset, length, src.length); + int indexWithOffset = applyOffset(index); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(src, offset, storage, applyOffset(index), length); + return this; + } + + public CharBufferImpl put(String src, int start, int end) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public CharBufferImpl compact() { + return super.compact(); + } + + String toString(int start, int end) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public CharBufferImpl subSequence(int start, int end) { + int pos = position(); + checkFromToIndex(start, end, limit() - pos); + return new HeapCharBufferImpl(storage, -1, pos + start, pos + end, capacity(), offset); + } + + public ByteOrder order() { + return ByteOrder.nativeOrder(); + } + + ByteOrder charRegionOrder() { + return order(); + } +} diff --git a/approximations/src/main/java/generated/java/util/HeapCharBufferRImpl.java b/approximations/src/main/java/generated/java/util/HeapCharBufferRImpl.java new file mode 100644 index 00000000..5abb9bca --- /dev/null +++ b/approximations/src/main/java/generated/java/util/HeapCharBufferRImpl.java @@ -0,0 +1,101 @@ +package generated.java.util; + +import jdk.internal.access.foreign.MemorySegmentProxy; +import org.jacodb.approximation.annotation.Approximate; + +import java.nio.*; +import java.util.Objects; + +@Approximate(stub.java.util.HeapCharBufferR.class) +public class HeapCharBufferRImpl extends HeapCharBufferImpl { + HeapCharBufferRImpl(int cap, int lim) { + super(cap, lim); + this.isReadOnly = true; + } + + HeapCharBufferRImpl(char[] buf, int off, int len) { + super(buf, off, len); + this.isReadOnly = true; + } + + protected HeapCharBufferRImpl(char[] buf, int mark, int pos, int lim, int cap, int off) { + super(buf, mark, pos, lim, cap, off); + this.isReadOnly = true; + } + + public CharBufferImpl slice() { + int pos = this.position(); + int lim = this.limit(); + int rem = (pos <= lim ? lim - pos : 0); + return new HeapCharBufferRImpl(storage, -1, 0, rem, rem, pos + offset); + } + + @Override + public CharBufferImpl slice(int index, int length) { + checkFromIndexSize(index, length, limit()); + return new HeapCharBufferRImpl(storage, -1, 0, length, length, index + offset); + } + + public CharBufferImpl duplicate() { + return new HeapCharBufferRImpl(storage, this.markValue(), this.position(), this.limit(), this.capacity(), + offset); + } + + public CharBufferImpl asReadOnlyBuffer() { + return duplicate(); + } + + public boolean isReadOnly() { + return true; + } + + public CharBufferImpl put(char x) { + throw new ReadOnlyBufferException(); + } + + public CharBufferImpl put(int i, char x) { + throw new ReadOnlyBufferException(); + } + + public CharBufferImpl put(char[] src, int offset, int length) { + throw new ReadOnlyBufferException(); + } + + public CharBufferImpl put(CharBufferImpl src) { + throw new ReadOnlyBufferException(); + } + + public CharBufferImpl put(int index, CharBufferImpl src, int offset, int length) { + throw new ReadOnlyBufferException(); + } + + public CharBufferImpl put(int index, char[] src, int offset, int length) { + throw new ReadOnlyBufferException(); + } + + public CharBufferImpl put(String src, int start, int end) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public CharBufferImpl compact() { + throw new ReadOnlyBufferException(); + } + + String toString(int start, int end) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public CharBufferImpl subSequence(int start, int end) { + int pos = position(); + checkFromToIndex(start, end, limit() - pos); + return new HeapCharBufferRImpl(storage, -1, pos + start, pos + end, capacity(), offset); + } + + public ByteOrder order() { + return ByteOrder.nativeOrder(); + } + + ByteOrder charRegionOrder() { + return order(); + } +} diff --git a/approximations/src/main/java/generated/java/util/HeapFloatBufferImpl.java b/approximations/src/main/java/generated/java/util/HeapFloatBufferImpl.java new file mode 100644 index 00000000..66f88f74 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/HeapFloatBufferImpl.java @@ -0,0 +1,124 @@ +package generated.java.util; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +import java.nio.BufferOverflowException; +import java.nio.BufferUnderflowException; +import java.nio.ByteOrder; + +@Approximate(stub.java.util.HeapFloatBuffer.class) +public class HeapFloatBufferImpl extends FloatBufferImpl { + HeapFloatBufferImpl(int cap, int lim) { + super(-1, 0, lim, cap, new float[cap], 0); + } + + HeapFloatBufferImpl(float[] buf, int off, int len) { + super(-1, off, off + len, buf.length, buf, 0); + } + + protected HeapFloatBufferImpl(float[] buf, int mark, int pos, int lim, int cap, int off) { + super(mark, pos, lim, cap, buf, off); + } + + public FloatBufferImpl slice() { + int pos = this.position(); + int lim = this.limit(); + int rem = (pos <= lim ? lim - pos : 0); + return new HeapFloatBufferImpl(storage, -1, 0, rem, rem, pos + offset); + } + + @Override + public FloatBufferImpl slice(int index, int length) { + checkFromIndexSize(index, length, limit()); + return new HeapFloatBufferImpl(storage, -1, 0, length, length, index + offset); + } + + public FloatBufferImpl duplicate() { + return new HeapFloatBufferImpl(storage, this.markValue(), this.position(), this.limit(), this.capacity(), offset); + } + + public FloatBufferImpl asReadOnlyBuffer() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public float get() { + return super.get(); + } + + public float get(int i) { + return super.get(i); + } + + public FloatBufferImpl get(float[] dst, int offset, int length) { + checkFromIndexSize(offset, length, dst.length); + int pos = position(); + if (length > limit() - pos) + throw new BufferUnderflowException(); + int indexWithOffset = applyOffset(pos); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(storage, applyOffset(pos), dst, offset, length); + position(pos + length); + return this; + } + + public FloatBufferImpl get(int index, float[] dst, int offset, int length) { + return super.get(index, dst, offset, length); + } + + public boolean isDirect() { + return false; + } + + public boolean isReadOnly() { + return false; + } + + public FloatBufferImpl put(float x) { + return super.put(x); + } + + public FloatBufferImpl put(int i, float x) { + return super.put(i, x); + } + + public FloatBufferImpl put(float[] src, int offset, int length) { + checkFromIndexSize(offset, length, src.length); + int pos = position(); + if (length > limit() - pos) + throw new BufferOverflowException(); + int indexWithOffset = applyOffset(pos); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(src, offset, storage, indexWithOffset, length); + position(pos + length); + return this; + } + + public FloatBufferImpl put(FloatBufferImpl src) { + super.put(src); + return this; + } + + public FloatBufferImpl put(int index, FloatBufferImpl src, int offset, int length) { + super.put(index, src, offset, length); + return this; + } + + public FloatBufferImpl put(int index, float[] src, int offset, int length) { + checkFromIndexSize(index, length, limit()); + checkFromIndexSize(offset, length, src.length); + int indexWithOffset = applyOffset(index); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(src, offset, storage, applyOffset(index), length); + return this; + } + + public FloatBufferImpl compact() { + return super.compact(); + } + + public ByteOrder order() { + return ByteOrder.nativeOrder(); + } +} diff --git a/approximations/src/main/java/generated/java/util/HeapIntBufferImpl.java b/approximations/src/main/java/generated/java/util/HeapIntBufferImpl.java new file mode 100644 index 00000000..9f761101 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/HeapIntBufferImpl.java @@ -0,0 +1,123 @@ +package generated.java.util; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +import java.nio.*; + +@Approximate(stub.java.util.HeapIntBuffer.class) +public class HeapIntBufferImpl extends IntBufferImpl { + HeapIntBufferImpl(int cap, int lim) { + super(-1, 0, lim, cap, new int[cap], 0); + } + + HeapIntBufferImpl(int[] buf, int off, int len) { + super(-1, off, off + len, buf.length, buf, 0); + } + + protected HeapIntBufferImpl(int[] buf, int mark, int pos, int lim, int cap, int off) { + super(mark, pos, lim, cap, buf, off); + } + + public IntBufferImpl slice() { + int pos = this.position(); + int lim = this.limit(); + int rem = (pos <= lim ? lim - pos : 0); + return new HeapIntBufferImpl(storage, -1, 0, rem, rem, pos + offset); + } + + @Override + public IntBufferImpl slice(int index, int length) { + checkFromIndexSize(index, length, limit()); + return new HeapIntBufferImpl(storage, -1, 0, length, length, index + offset); + } + + public IntBufferImpl duplicate() { + return new HeapIntBufferImpl(storage, this.markValue(), this.position(), this.limit(), this.capacity(), offset); + } + + public IntBufferImpl asReadOnlyBuffer() { + return new HeapIntBufferRImpl(storage, this.markValue(), this.position(), this.limit(), this.capacity(), + offset); + } + + public int get() { + return super.get(); + } + + public int get(int i) { + return super.get(i); + } + + public IntBufferImpl get(int[] dst, int offset, int length) { + checkFromIndexSize(offset, length, dst.length); + int pos = position(); + if (length > limit() - pos) + throw new BufferUnderflowException(); + int indexWithOffset = applyOffset(pos); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(storage, applyOffset(pos), dst, offset, length); + position(pos + length); + return this; + } + + public IntBufferImpl get(int index, int[] dst, int offset, int length) { + return super.get(index, dst, offset, length); + } + + public boolean isDirect() { + return false; + } + + public boolean isReadOnly() { + return false; + } + + public IntBufferImpl put(int x) { + return super.put(x); + } + + public IntBufferImpl put(int i, int x) { + return super.put(i, x); + } + + public IntBufferImpl put(int[] src, int offset, int length) { + checkFromIndexSize(offset, length, src.length); + int pos = position(); + if (length > limit() - pos) + throw new BufferOverflowException(); + int indexWithOffset = applyOffset(pos); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(src, offset, storage, indexWithOffset, length); + position(pos + length); + return this; + } + + public IntBufferImpl put(IntBufferImpl src) { + super.put(src); + return this; + } + + public IntBufferImpl put(int index, IntBufferImpl src, int offset, int length) { + super.put(index, src, offset, length); + return this; + } + + public IntBufferImpl put(int index, int[] src, int offset, int length) { + checkFromIndexSize(index, length, limit()); + checkFromIndexSize(offset, length, src.length); + int indexWithOffset = applyOffset(index); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(src, offset, storage, applyOffset(index), length); + return this; + } + + public IntBufferImpl compact() { + return super.compact(); + } + + public ByteOrder order() { + return ByteOrder.nativeOrder(); + } +} diff --git a/approximations/src/main/java/generated/java/util/HeapIntBufferRImpl.java b/approximations/src/main/java/generated/java/util/HeapIntBufferRImpl.java new file mode 100644 index 00000000..33d10523 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/HeapIntBufferRImpl.java @@ -0,0 +1,82 @@ +package generated.java.util; + +import org.jacodb.approximation.annotation.Approximate; + +import java.nio.ByteOrder; +import java.nio.ReadOnlyBufferException; + +@Approximate(stub.java.util.HeapIntBufferR.class) +public class HeapIntBufferRImpl extends HeapIntBufferImpl { + HeapIntBufferRImpl(int cap, int lim) { + super(cap, lim); + this.isReadOnly = true; + } + + HeapIntBufferRImpl(int[] buf, int off, int len) { + super(buf, off, len); + this.isReadOnly = true; + } + + protected HeapIntBufferRImpl(int[] buf, int mark, int pos, int lim, int cap, int off) { + super(buf, mark, pos, lim, cap, off); + this.isReadOnly = true; + } + + public IntBufferImpl slice() { + int pos = this.position(); + int lim = this.limit(); + int rem = (pos <= lim ? lim - pos : 0); + return new HeapIntBufferRImpl(storage, -1, 0, rem, rem, pos + offset); + } + + @Override + public IntBufferImpl slice(int index, int length) { + checkFromIndexSize(index, length, limit()); + return new HeapIntBufferRImpl(storage, -1, 0, length, length, index + offset); + } + + public IntBufferImpl duplicate() { + return new HeapIntBufferRImpl(storage, this.markValue(), this.position(), this.limit(), this.capacity(), + offset); + } + + public IntBufferImpl asReadOnlyBuffer() { + return duplicate(); + } + + public boolean isReadOnly() { + return true; + } + + public IntBufferImpl put(int x) { + throw new ReadOnlyBufferException(); + } + + public IntBufferImpl put(int i, int x) { + throw new ReadOnlyBufferException(); + } + + public IntBufferImpl put(int[] src, int offset, int length) { + throw new ReadOnlyBufferException(); + } + + public IntBufferImpl put(IntBufferImpl src) { + throw new ReadOnlyBufferException(); + } + + public IntBufferImpl put(int index, IntBufferImpl src, int offset, int length) { + throw new ReadOnlyBufferException(); + } + + public IntBufferImpl put(int index, int[] src, int offset, int length) { + throw new ReadOnlyBufferException(); + } + + public IntBufferImpl compact() { + throw new ReadOnlyBufferException(); + } + + public ByteOrder order() { + return ByteOrder.nativeOrder(); + } +} diff --git a/approximations/src/main/java/generated/java/util/IntBufferImpl.java b/approximations/src/main/java/generated/java/util/IntBufferImpl.java new file mode 100644 index 00000000..10c32666 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/IntBufferImpl.java @@ -0,0 +1,341 @@ +package generated.java.util; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +import java.nio.*; + +@Approximate(java.nio.IntBuffer.class) +public abstract class IntBufferImpl extends BufferImpl implements Comparable { + final int[] storage; + int offset; + boolean isReadOnly; + + IntBufferImpl(int mark, int pos, int lim, int cap, int[] hb, int offset) { + super(mark, pos, lim, cap); + this.storage = hb; + this.offset = offset; + } + + IntBufferImpl(int mark, int pos, int lim, int cap, int[] segment) { + this(mark, pos, lim, cap, segment, 0); + } + + IntBufferImpl(int[] hb, int cap) { + super(cap); + this.storage = hb; + this.offset = 0; + } + + @Override + Object base() { + return storage; + } + + public static IntBufferImpl allocate(int capacity) { + if (capacity < 0) + throw createCapacityException(capacity); + return new HeapIntBufferImpl(capacity, capacity); + } + + public static IntBufferImpl wrap(int[] array, int offset, int length) { + try { + return new HeapIntBufferImpl(array, offset, length); + } catch (IllegalArgumentException x) { + throw new IndexOutOfBoundsException(); + } + } + + public static IntBufferImpl wrap(int[] array) { + return wrap(array, 0, array.length); + } + + @Override + public abstract IntBufferImpl slice(); + + @Override + public abstract IntBufferImpl slice(int index, int length); + + @Override + public abstract IntBufferImpl duplicate(); + + public abstract IntBufferImpl asReadOnlyBuffer(); + + public int get() { + int indexWithOffset = applyOffset(nextGetIndex()); + Engine.assume(indexWithOffset < storage.length); + return storage[indexWithOffset]; + } + + public IntBufferImpl put(int i) { + int indexWithOffset = applyOffset(nextPutIndex()); + Engine.assume(indexWithOffset < storage.length); + storage[indexWithOffset] = i; + return this; + } + + public int get(int index) { + int indexWithOffset = applyOffset(checkIndex(index)); + Engine.assume(indexWithOffset < storage.length); + return storage[indexWithOffset]; + } + + public IntBufferImpl put(int index, int i) { + int indexWithOffset = applyOffset(checkIndex(index)); + Engine.assume(indexWithOffset < storage.length); + storage[indexWithOffset] = i; + return this; + } + + public IntBufferImpl get(int[] dst, int offset, int length) { + checkFromIndexSize(offset, length, dst.length); + if (length > remaining()) + throw new BufferUnderflowException(); + int indexWithOffset = applyOffset(nextGetIndex(length)); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(storage, indexWithOffset, dst, offset, length); + return this; + } + + public IntBufferImpl get(int[] dst) { + return get(dst, 0, dst.length); + } + + public IntBufferImpl get(int index, int[] dst, int offset, int length) { + checkFromIndexSize(index, length, limit()); + checkFromIndexSize(offset, length, dst.length); + int indexWithOffset = applyOffset(nextGetIndex(length)); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(storage, indexWithOffset, dst, offset, length); + return this; + } + + public IntBufferImpl get(int index, int[] dst) { + return get(index, dst, 0, dst.length); + } + + public IntBufferImpl put(IntBufferImpl src) { + if (src == this) + throw createSameBufferException(); + if (isReadOnly()) + throw new ReadOnlyBufferException(); + + int srcPos = src.position(); + int srcLim = src.limit(); + int srcRem = (srcPos <= srcLim ? srcLim - srcPos : 0); + int pos = position(); + int lim = limit(); + int rem = (pos <= lim ? lim - pos : 0); + + if (srcRem > rem) + throw new BufferOverflowException(); + + putBuffer(pos, src, srcPos, srcRem); + + position(pos + srcRem); + src.position(srcPos + srcRem); + + return this; + } + + public IntBufferImpl put(int index, IntBufferImpl src, int offset, int length) { + checkFromIndexSize(index, length, limit()); + checkFromIndexSize(offset, length, src.limit()); + if (isReadOnly()) + throw new ReadOnlyBufferException(); + + putBuffer(index, src, offset, length); + + return this; + } + + void putBuffer(int pos, IntBufferImpl src, int srcPos, int n) { + Object srcBase = src.base(); + assert srcBase != null || src.isDirect(); + Object base = base(); + assert base != null || isDirect(); + int indexWithOffset = applyOffset(pos); + int srcIndexWithOffset = src.applyOffset(srcPos); + Engine.assume(indexWithOffset + n < storage.length); + Engine.assume(srcIndexWithOffset + n < src.storage.length); + LibSLRuntime.ArrayActions.copy(src.storage, srcIndexWithOffset, storage, indexWithOffset, n); + } + + public IntBufferImpl put(int[] src, int offset, int length) { + checkFromIndexSize(offset, length, src.length); + if (length > remaining()) + throw new BufferOverflowException(); + int indexWithOffset = applyOffset(nextPutIndex(length)); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(src, offset, storage, indexWithOffset, length); + return this; + } + + public final IntBufferImpl put(int[] src) { + return put(src, 0, src.length); + } + + public IntBufferImpl put(int index, int[] src, int offset, int length) { + if (isReadOnly()) + throw new ReadOnlyBufferException(); + checkFromIndexSize(index, length, limit()); + checkFromIndexSize(offset, length, src.length); + int indexWithOffset = applyOffset(index); + Engine.assume(indexWithOffset + length < storage.length); + LibSLRuntime.ArrayActions.copy(src, offset, storage, indexWithOffset, length); + return this; + } + + public IntBufferImpl put(int index, int[] src) { + return put(index, src, 0, src.length); + } + + public final boolean hasArray() { + return (storage != null) && !isReadOnly; + } + + public final int[] array() { + if (storage == null) + throw new UnsupportedOperationException(); + if (isReadOnly) + throw new ReadOnlyBufferException(); + return storage; + } + + public final int arrayOffset() { + if (storage == null) + throw new UnsupportedOperationException(); + if (isReadOnly) + throw new ReadOnlyBufferException(); + return offset; + } + + @Override + public final IntBufferImpl position(int newPosition) { + super.position(newPosition); + return this; + } + + @Override + public final IntBufferImpl limit(int newLimit) { + super.limit(newLimit); + return this; + } + + @Override + public final IntBufferImpl mark() { + super.mark(); + return this; + } + + @Override + public final IntBufferImpl reset() { + super.reset(); + return this; + } + + @Override + public final IntBufferImpl clear() { + super.clear(); + return this; + } + + @Override + public final IntBufferImpl flip() { + super.flip(); + return this; + } + + @Override + public final IntBufferImpl rewind() { + super.rewind(); + return this; + } + + public IntBufferImpl compact() { + int pos = position(); + int lim = limit(); + assert (pos <= lim); + int rem = lim - pos; + int srcIndexWithOffset = applyOffset(pos); + int dstIndexWithOffset = applyOffset(0); + Engine.assume(srcIndexWithOffset + rem < storage.length); + Engine.assume(dstIndexWithOffset + rem < storage.length); + LibSLRuntime.ArrayActions.copy(storage, srcIndexWithOffset, storage, dstIndexWithOffset, rem); + position(rem); + limit(capacity()); + discardMark(); + return this; + } + + public abstract boolean isDirect(); + + public String toString() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public int hashCode() { + int h = 1; + int p = position(); + for (int i = limit() - 1; i >= p; i--) + h = 31 * h + get(i); + return h; + } + + private int mismatch(IntBufferImpl a, int aOff, IntBufferImpl b, int bOff, int length) { + for (int i = 0; i < length; i++) { + if (a.get(aOff + i) != b.get(bOff + i)) + return i; + } + return -1; + } + + public boolean equals(Object ob) { + if (this == ob) + return true; + if (!(ob instanceof IntBuffer)) + return false; + IntBufferImpl that = (IntBufferImpl)ob; + int thisPos = this.position(); + int thisRem = this.limit() - thisPos; + int thatPos = that.position(); + int thatRem = that.limit() - thatPos; + if (thisRem < 0 || thisRem != thatRem) + return false; + return mismatch(this, thisPos, that, thatPos, thisRem) < 0; + } + + public int compareTo(IntBufferImpl that) { + int thisPos = this.position(); + int thisRem = this.limit() - thisPos; + int thatPos = that.position(); + int thatRem = that.limit() - thatPos; + int length = thisRem < thatRem ? thisRem : thatRem; + if (length < 0) + return -1; + int i = mismatch(this, thisPos, that, thatPos, length); + if (i >= 0) { + return compare(this.get(thisPos + i), that.get(thatPos + i)); + } + return thisRem - thatRem; + } + + private static int compare(int x, int y) { + return (x < y) ? -1 : ((x == y) ? 0 : 1); + } + + public int mismatch(IntBufferImpl that) { + int thisPos = this.position(); + int thisRem = this.limit() - thisPos; + int thatPos = that.position(); + int thatRem = that.limit() - thatPos; + int length = thisRem < thatRem ? thisRem : thatRem; + if (length < 0) + return -1; + int r = mismatch(this, thisPos, that, thatPos, length); + return (r == -1 && thisRem != thatRem) ? length : r; + } + + public abstract ByteOrder order(); +} diff --git a/approximations/src/main/java/generated/java/util/LinkedHashSet.java b/approximations/src/main/java/generated/java/util/LinkedHashSet.java deleted file mode 100644 index 95b5075d..00000000 --- a/approximations/src/main/java/generated/java/util/LinkedHashSet.java +++ /dev/null @@ -1,745 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/LinkedHashSet.lsl:20 -// - java/util/LinkedHashSet.main.lsl:25 -// -package generated.java.util; - -import generated.runtime.LibSLGlobals; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.lang.Cloneable; -import java.lang.IllegalArgumentException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Collection; -import java.util.ConcurrentModificationException; -import java.util.Iterator; -import java.util.Set; -import java.util.Spliterator; -import java.util.function.Consumer; -import java.util.function.IntFunction; -import java.util.function.Predicate; -import java.util.stream.Stream; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; -import stub.java.util.stream.StreamLSL; - -/** - * LinkedHashSetAutomaton for LinkedHashSet ~> java.util.LinkedHashSet - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.util.LinkedHashSet.class) -public class LinkedHashSet implements LibSLRuntime.Automaton, Set, Cloneable, Serializable { - private static final long serialVersionUID = -2851667679971038690L; - - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public LibSLRuntime.Map storage; - - public transient int modCount; - - @LibSLRuntime.AutomatonConstructor - public LinkedHashSet(Void __$lsl_token, final byte p0, - final LibSLRuntime.Map p1, final int p2) { - this.__$lsl_state = p0; - this.storage = p1; - this.modCount = p2; - } - - @LibSLRuntime.AutomatonConstructor - public LinkedHashSet(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, null, 0); - } - - /** - * [CONSTRUCTOR] LinkedHashSetAutomaton::(LinkedHashSet) -> void - * Source: java/util/LinkedHashSet.main.lsl:156 - */ - public LinkedHashSet() { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.storage = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] LinkedHashSetAutomaton::(LinkedHashSet, Collection) -> void - * Source: java/util/LinkedHashSet.main.lsl:162 - */ - public LinkedHashSet(Collection c) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.storage = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - _addAllElements(c); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] LinkedHashSetAutomaton::(LinkedHashSet, int) -> void - * Source: java/util/LinkedHashSet.main.lsl:169 - */ - public LinkedHashSet(int initialCapacity) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - if (initialCapacity < 0) { - throw new IllegalArgumentException(); - } - this.storage = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] LinkedHashSetAutomaton::(LinkedHashSet, int, float) -> void - * Source: java/util/LinkedHashSet.main.lsl:181 - */ - public LinkedHashSet(int initialCapacity, float loadFactor) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - if (initialCapacity < 0) { - throw new IllegalArgumentException(); - } - if ((loadFactor <= 0) || (loadFactor != loadFactor)) { - throw new IllegalArgumentException(); - } - this.storage = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] LinkedHashSetAutomaton::_checkForComodification(int) -> void - * Source: java/util/LinkedHashSet.main.lsl:78 - */ - public void _checkForComodification(int expectedModCount) { - /* body */ { - if (this.modCount != expectedModCount) { - throw new ConcurrentModificationException(); - } - } - } - - /** - * [SUBROUTINE] LinkedHashSetAutomaton::_addAllElements(Collection) -> boolean - * Source: java/util/LinkedHashSet.main.lsl:85 - */ - private boolean _addAllElements(Collection c) { - boolean result = false; - /* body */ { - final int lengthBeforeAdd = this.storage.size(); - final Iterator iter = c.iterator(); - while (iter.hasNext()) { - final Object key = iter.next(); - if (!this.storage.hasKey(key)) { - this.storage.set(key, LibSLGlobals.SOMETHING); - } - } - ; - if (lengthBeforeAdd != this.storage.size()) { - this.modCount += 1; - result = true; - } else { - result = false; - } - } - return result; - } - - /** - * [SUBROUTINE] LinkedHashSetAutomaton::_makeStream(boolean) -> Stream - * Source: java/util/LinkedHashSet.main.lsl:122 - */ - private Stream _makeStream(boolean parallel) { - Stream result = null; - /* body */ { - final LibSLRuntime.Map unseen = this.storage.duplicate(); - final int count = unseen.size(); - final Object[] items = new Object[count]; - int i = 0; - for (i = 0; i < count; i += 1) { - final Object key = unseen.anyKey(); - unseen.remove(key); - items[i] = key; - } - ; - result = (StreamLSL) ((Object) new generated.java.util.stream.StreamLSL((Void) null, - /* state = */ generated.java.util.stream.StreamLSL.__$lsl_States.Initialized, - /* storage = */ items, - /* length = */ count, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ parallel, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::add(LinkedHashSet, Object) -> boolean - * Source: java/util/LinkedHashSet.main.lsl:201 - */ - public boolean add(Object obj) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final boolean hasKey = this.storage.hasKey(obj); - if (hasKey) { - result = false; - } else { - this.storage.set(obj, LibSLGlobals.SOMETHING); - result = true; - } - this.modCount += 1; - } - return result; - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::clear(LinkedHashSet) -> void - * Source: java/util/LinkedHashSet.main.lsl:219 - */ - public void clear() { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.storage = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - this.modCount += 1; - } - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::clone(LinkedHashSet) -> Object - * Source: java/util/LinkedHashSet.main.lsl:226 - */ - public Object clone() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (java.util.LinkedHashSet) ((Object) new LinkedHashSet((Void) null, - /* state = */ LinkedHashSet.__$lsl_States.Initialized, - /* storage = */ this.storage.duplicate(), - /* modCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::contains(LinkedHashSet, Object) -> boolean - * Source: java/util/LinkedHashSet.main.lsl:234 - */ - public boolean contains(Object obj) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.storage.size() == 0) { - result = false; - } else { - result = this.storage.hasKey(obj); - } - } - return result; - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::isEmpty(LinkedHashSet) -> boolean - * Source: java/util/LinkedHashSet.main.lsl:243 - */ - public boolean isEmpty() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.storage.size() == 0; - } - return result; - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::iterator(LinkedHashSet) -> Iterator - * Source: java/util/LinkedHashSet.main.lsl:249 - */ - public Iterator iterator() { - Iterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final LibSLRuntime.Map unseenKeys = this.storage.duplicate(); - result = (stub.java.util.LinkedHashSet_KeyIterator) ((Object) new LinkedHashSet_KeyIterator((Void) null, - /* state = */ LinkedHashSet_KeyIterator.__$lsl_States.Initialized, - /* expectedModCount = */ this.modCount, - /* unseenKeys = */ unseenKeys, - /* parent = */ this, - /* index = */ 0, - /* currentKey = */ 0, - /* nextWasCalled = */ false - )); - } - return result; - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::remove(LinkedHashSet, Object) -> boolean - * Source: java/util/LinkedHashSet.main.lsl:260 - */ - public boolean remove(Object obj) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.storage.hasKey(obj)) { - this.storage.remove(obj); - this.modCount += 1; - result = true; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::size(LinkedHashSet) -> int - * Source: java/util/LinkedHashSet.main.lsl:275 - */ - public int size() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.storage.size(); - } - return result; - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::spliterator(LinkedHashSet) -> Spliterator - * Source: java/util/LinkedHashSet.main.lsl:281 - */ - public Spliterator spliterator() { - Spliterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final Object[] keysStorageArray = new Object[this.storage.size()]; - final LibSLRuntime.Map unseenKeys = this.storage.duplicate(); - int i = 0; - for (i = 0; i < this.storage.size(); i += 1) { - final Object key = unseenKeys.anyKey(); - unseenKeys.remove(key); - keysStorageArray[i] = key; - } - ; - result = (stub.java.util.LinkedHashSet_KeySpliterator) ((Object) new LinkedHashSet_KeySpliterator((Void) null, - /* state = */ LinkedHashSet_KeySpliterator.__$lsl_States.Initialized, - /* keysStorage = */ keysStorageArray, - /* index = */ 0, - /* fence = */ -1, - /* est = */ 0, - /* expectedModCount = */ this.modCount, - /* parent = */ this - )); - } - return result; - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::equals(LinkedHashSet, Object) -> boolean - * Source: java/util/LinkedHashSet.main.lsl:312 - */ - public boolean equals(Object other) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (other == this) { - result = true; - } else { - if ((other != null && other.getClass() == java.util.LinkedHashSet.class)) { - final int expectedModCount = this.modCount; - final int otherExpectedModCount = ((LinkedHashSet) ((Object) other)).modCount; - final LibSLRuntime.Map otherStorage = ((LinkedHashSet) ((Object) other)).storage; - if (this.storage.size() == otherStorage.size()) { - result = LibSLRuntime.equals(this.storage, otherStorage); - } else { - result = false; - } - ((LinkedHashSet) ((Object) other))._checkForComodification(otherExpectedModCount); - _checkForComodification(expectedModCount); - } else { - result = false; - } - } - } - return result; - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::hashCode(LinkedHashSet) -> int - * Source: java/util/LinkedHashSet.main.lsl:343 - */ - public int hashCode() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = LibSLRuntime.hashCode(this.storage); - } - return result; - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::removeAll(LinkedHashSet, Collection) -> boolean - * Source: java/util/LinkedHashSet.main.lsl:349 - */ - public boolean removeAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (c == null) { - throw new NullPointerException(); - } - final int expectedModCount = this.modCount; - final int otherSize = c.size(); - final Iterator iter = c.iterator(); - final int lengthBeforeRemoving = this.storage.size(); - int i = 0; - if (this.storage.size() > otherSize) { - while (iter.hasNext()) { - final Object key = iter.next(); - if (this.storage.hasKey(key)) { - this.storage.remove(key); - } - } - ; - } else { - final LibSLRuntime.Map unseenKeys = this.storage.duplicate(); - while (i < lengthBeforeRemoving) { - final Object key = unseenKeys.anyKey(); - unseenKeys.remove(key); - if (c.contains(key)) { - this.storage.remove(key); - } - i += 1; - } - ; - } - _checkForComodification(expectedModCount); - this.modCount += 1; - result = lengthBeforeRemoving != this.storage.size(); - } - return result; - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::toArray(LinkedHashSet) -> array - * Source: java/util/LinkedHashSet.main.lsl:404 - */ - public Object[] toArray() { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int len = this.storage.size(); - result = new Object[len]; - final int expectedModCount = this.modCount; - final LibSLRuntime.Map unseenKeys = this.storage.duplicate(); - int i = 0; - for (i = 0; i < len; i += 1) { - final Object key = unseenKeys.anyKey(); - unseenKeys.remove(key); - result[i] = key; - } - ; - _checkForComodification(expectedModCount); - } - return result; - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::toArray(LinkedHashSet, array) -> array - * Source: java/util/LinkedHashSet.main.lsl:430 - */ - public Object[] toArray(Object[] a) { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int expectedModCount = this.modCount; - final int aLen = a.length; - final int len = this.storage.size(); - final LibSLRuntime.Map unseenKeys = this.storage.duplicate(); - int i = 0; - if (aLen < len) { - a = new Object[len]; - } - result = a; - for (i = 0; i < len; i += 1) { - final Object key = unseenKeys.anyKey(); - unseenKeys.remove(key); - result[i] = key; - } - ; - if (aLen > len) { - result[len] = null; - } - _checkForComodification(expectedModCount); - } - return result; - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::toArray(LinkedHashSet, IntFunction) -> array - * Source: java/util/LinkedHashSet.main.lsl:455 - */ - public Object[] toArray(IntFunction generator) { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (generator == null) { - throw new NullPointerException(); - } - final int len = this.storage.size(); - result = ((Object[]) generator.apply(0)); - final int expectedModCount = this.modCount; - final LibSLRuntime.Map unseenKeys = this.storage.duplicate(); - int i = 0; - for (i = 0; i < len; i += 1) { - final Object key = unseenKeys.anyKey(); - unseenKeys.remove(key); - result[i] = key; - } - ; - _checkForComodification(expectedModCount); - } - return result; - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::containsAll(LinkedHashSet, Collection) -> boolean - * Source: java/util/LinkedHashSet.main.lsl:475 - */ - public boolean containsAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int otherSize = c.size(); - final Iterator iter = c.iterator(); - boolean isContainsAll = true; - while (iter.hasNext()) { - final Object key = iter.next(); - final boolean isKeyExist = this.storage.hasKey(key); - if (!isKeyExist) { - isContainsAll = false; - break; - } - } - ; - result = isContainsAll; - } - return result; - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::addAll(LinkedHashSet, Collection) -> boolean - * Source: java/util/LinkedHashSet.main.lsl:503 - */ - public boolean addAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _addAllElements(c); - } - return result; - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::retainAll(LinkedHashSet, Collection) -> boolean - * Source: java/util/LinkedHashSet.main.lsl:509 - */ - public boolean retainAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (c == null) { - throw new NullPointerException(); - } - final int lengthBeforeAdd = this.storage.size(); - final LibSLRuntime.Map unseenKeys = this.storage.duplicate(); - int i = 0; - while (i < lengthBeforeAdd) { - final Object key = unseenKeys.anyKey(); - unseenKeys.remove(key); - if (!c.contains(key)) { - this.storage.remove(key); - } - i += 1; - } - ; - if (lengthBeforeAdd != this.storage.size()) { - this.modCount += 1; - result = true; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::removeIf(LinkedHashSet, Predicate) -> boolean - * Source: java/util/LinkedHashSet.main.lsl:547 - */ - public boolean removeIf(Predicate filter) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (filter == null) { - throw new NullPointerException(); - } - final int lengthBeforeAdd = this.storage.size(); - final int expectedModCount = this.modCount; - int i = 0; - final LibSLRuntime.Map unseenKeys = this.storage.duplicate(); - while (i < lengthBeforeAdd) { - final Object key = unseenKeys.anyKey(); - unseenKeys.remove(key); - if (filter.test(key)) { - this.storage.remove(key); - } - i += 1; - } - ; - _checkForComodification(expectedModCount); - if (lengthBeforeAdd != this.storage.size()) { - this.modCount += 1; - result = true; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::forEach(LinkedHashSet, Consumer) -> void - * Source: java/util/LinkedHashSet.main.lsl:587 - */ - public void forEach(Consumer userAction) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (userAction == null) { - throw new NullPointerException(); - } - int i = 0; - final int expectedModCount = this.modCount; - final LibSLRuntime.Map unseenKeys = this.storage.duplicate(); - while (i < this.storage.size()) { - final Object key = unseenKeys.anyKey(); - unseenKeys.remove(key); - userAction.accept(key); - i += 1; - } - ; - _checkForComodification(expectedModCount); - } - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::stream(LinkedHashSet) -> Stream - * Source: java/util/LinkedHashSet.main.lsl:617 - */ - public Stream stream() { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _makeStream(false); - } - return result; - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::parallelStream(LinkedHashSet) -> Stream - * Source: java/util/LinkedHashSet.main.lsl:624 - */ - public Stream parallelStream() { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _makeStream(true); - } - return result; - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::writeObject(LinkedHashSet, ObjectOutputStream) -> void - * Source: java/util/LinkedHashSet.main.lsl:632 - */ - private void writeObject(ObjectOutputStream s) throws java.io.IOException { - /* body */ { - LibSLRuntime.not_implemented(/* no serialization support yet */); - } - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::readObject(LinkedHashSet, ObjectInputStream) -> void - * Source: java/util/LinkedHashSet.main.lsl:639 - */ - private void readObject(ObjectInputStream s) throws java.io.IOException, - java.lang.ClassNotFoundException { - /* body */ { - LibSLRuntime.not_implemented(/* no serialization support yet */); - } - } - - /** - * [FUNCTION] LinkedHashSetAutomaton::toString(LinkedHashSet) -> String - * Source: java/util/LinkedHashSet.main.lsl:647 - */ - public String toString() { - String result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final LibSLRuntime.Map items = this.storage; - int count = items.size(); - if (count == 0) { - result = "[]"; - } else { - Engine.assume(count > 0); - result = "["; - final LibSLRuntime.Map unseen = items.duplicate(); - while (count != 0) { - final Object key = unseen.anyKey(); - unseen.remove(key); - result = result.concat(LibSLRuntime.toString(key)); - if (count > 1) { - result = result.concat(", "); - } - count -= 1; - } - ; - result = result.concat("]"); - } - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(LinkedHashSet.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/LinkedHashSet_KeyIterator.java b/approximations/src/main/java/generated/java/util/LinkedHashSet_KeyIterator.java deleted file mode 100644 index 60200543..00000000 --- a/approximations/src/main/java/generated/java/util/LinkedHashSet_KeyIterator.java +++ /dev/null @@ -1,190 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/LinkedHashSet.lsl:39 -// - java/util/LinkedHashSet.KeyIterator.lsl:19 -// -package generated.java.util; - -import java.lang.IllegalStateException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ConcurrentModificationException; -import java.util.Iterator; -import java.util.NoSuchElementException; -import java.util.function.Consumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * LinkedHashSet_KeyIteratorAutomaton for LinkedHashSet_KeyIterator ~> java.util.LinkedHashSet_KeyIterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.LinkedHashSet_KeyIterator.class) -public final class LinkedHashSet_KeyIterator implements LibSLRuntime.Automaton, Iterator { - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public int expectedModCount; - - public LibSLRuntime.Map unseenKeys; - - public LinkedHashSet parent; - - public int index; - - public Object currentKey; - - public boolean nextWasCalled; - - @LibSLRuntime.AutomatonConstructor - public LinkedHashSet_KeyIterator(Void __$lsl_token, final byte p0, final int p1, - final LibSLRuntime.Map p2, final LinkedHashSet p3, final int p4, - final Object p5, final boolean p6) { - this.__$lsl_state = p0; - this.expectedModCount = p1; - this.unseenKeys = p2; - this.parent = p3; - this.index = p4; - this.currentKey = p5; - this.nextWasCalled = p6; - } - - @LibSLRuntime.AutomatonConstructor - public LinkedHashSet_KeyIterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, 0, null, null, 0, 0, false); - } - - /** - * [CONSTRUCTOR] LinkedHashSet_KeyIteratorAutomaton::(LinkedHashSet_KeyIterator, HashMap) -> void - * Source: java/util/LinkedHashSet.KeyIterator.lsl:65 - */ - private LinkedHashSet_KeyIterator(HashMap source) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - LibSLRuntime.error("Private constructor call"); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] LinkedHashSet_KeyIteratorAutomaton::_checkForComodification() -> void - * Source: java/util/LinkedHashSet.KeyIterator.lsl:55 - */ - private void _checkForComodification() { - /* body */ { - final int modCount = ((LinkedHashSet) ((Object) this.parent)).modCount; - if (this.expectedModCount != modCount) { - throw new ConcurrentModificationException(); - } - } - } - - /** - * [FUNCTION] LinkedHashSet_KeyIteratorAutomaton::hasNext(LinkedHashSet_KeyIterator) -> boolean - * Source: java/util/LinkedHashSet.KeyIterator.lsl:73 - */ - public boolean hasNext() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.parent != null); - final LibSLRuntime.Map parentStorage = ((LinkedHashSet) ((Object) this.parent)).storage; - result = this.index < parentStorage.size(); - } - return result; - } - - /** - * [FUNCTION] LinkedHashSet_KeyIteratorAutomaton::next(LinkedHashSet_KeyIterator) -> Object - * Source: java/util/LinkedHashSet.KeyIterator.lsl:83 - */ - public final Object next() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.parent != null); - _checkForComodification(); - final LibSLRuntime.Map parentStorage = ((LinkedHashSet) ((Object) this.parent)).storage; - final boolean atValidPosition = this.index < parentStorage.size(); - if (!atValidPosition) { - throw new NoSuchElementException(); - } - final Object key = this.unseenKeys.anyKey(); - this.unseenKeys.remove(key); - this.currentKey = key; - result = key; - this.index += 1; - this.nextWasCalled = true; - } - return result; - } - - /** - * [FUNCTION] LinkedHashSet_KeyIteratorAutomaton::remove(LinkedHashSet_KeyIterator) -> void - * Source: java/util/LinkedHashSet.KeyIterator.lsl:105 - */ - public void remove() { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.parent != null); - final LibSLRuntime.Map parentStorage = ((LinkedHashSet) ((Object) this.parent)).storage; - final boolean atValidPosition = this.index < parentStorage.size(); - if (!atValidPosition || !this.nextWasCalled) { - throw new IllegalStateException(); - } - this.nextWasCalled = false; - _checkForComodification(); - parentStorage.remove(this.currentKey); - this.expectedModCount = ((LinkedHashSet) ((Object) this.parent)).modCount; - } - } - - /** - * [FUNCTION] LinkedHashSet_KeyIteratorAutomaton::forEachRemaining(LinkedHashSet_KeyIterator, Consumer) -> void - * Source: java/util/LinkedHashSet.KeyIterator.lsl:125 - */ - public void forEachRemaining(Consumer userAction) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.parent != null); - if (userAction == null) { - throw new NullPointerException(); - } - final LibSLRuntime.Map parentStorage = ((LinkedHashSet) ((Object) this.parent)).storage; - final int length = parentStorage.size(); - int i = this.index; - while (i < length) { - _checkForComodification(); - final Object key = this.unseenKeys.anyKey(); - this.unseenKeys.remove(key); - Engine.assume(key != this.currentKey); - this.currentKey = key; - userAction.accept(key); - i += 1; - } - ; - this.index = i; - this.nextWasCalled = true; - } - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(LinkedHashSet_KeyIterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/LinkedHashSet_KeySpliterator.java b/approximations/src/main/java/generated/java/util/LinkedHashSet_KeySpliterator.java deleted file mode 100644 index 96985a89..00000000 --- a/approximations/src/main/java/generated/java/util/LinkedHashSet_KeySpliterator.java +++ /dev/null @@ -1,254 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/LinkedHashSet.lsl:31 -// - java/util/LinkedHashSet.Spliterator.lsl:19 -// -package generated.java.util; - -import generated.runtime.LibSLGlobals; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ConcurrentModificationException; -import java.util.Spliterator; -import java.util.function.Consumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * LinkedHashSet_KeySpliteratorAutomaton for LinkedHashSet_KeySpliterator ~> java.util.LinkedHashSet_KeySpliterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.LinkedHashSet_KeySpliterator.class) -public final class LinkedHashSet_KeySpliterator implements LibSLRuntime.Automaton, Spliterator { - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public Object[] keysStorage; - - public int index; - - public int fence; - - public int est; - - public int expectedModCount; - - public LinkedHashSet parent; - - @LibSLRuntime.AutomatonConstructor - public LinkedHashSet_KeySpliterator(Void __$lsl_token, final byte p0, final Object[] p1, - final int p2, final int p3, final int p4, final int p5, final LinkedHashSet p6) { - this.__$lsl_state = p0; - this.keysStorage = p1; - this.index = p2; - this.fence = p3; - this.est = p4; - this.expectedModCount = p5; - this.parent = p6; - } - - @LibSLRuntime.AutomatonConstructor - public LinkedHashSet_KeySpliterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, null, 0, 0, 0, 0, null); - } - - /** - * [CONSTRUCTOR] LinkedHashSet_KeySpliteratorAutomaton::(LinkedHashSet_KeySpliterator, HashMap, int, int, int, int) -> void - * Source: java/util/LinkedHashSet.Spliterator.lsl:89 - */ - private LinkedHashSet_KeySpliterator(HashMap source, int origin, int fence, int est, - int expectedModCount) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.index = origin; - fence = fence; - est = est; - expectedModCount = expectedModCount; - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] LinkedHashSet_KeySpliteratorAutomaton::_getFence() -> int - * Source: java/util/LinkedHashSet.Spliterator.lsl:54 - */ - private int _getFence() { - int result = 0; - /* body */ { - Engine.assume(this.parent != null); - int hi = this.fence; - if (hi < 0) { - final LibSLRuntime.Map parentStorage = ((LinkedHashSet) ((Object) this.parent)).storage; - this.est = parentStorage.size(); - this.expectedModCount = ((LinkedHashSet) ((Object) this.parent)).modCount; - this.fence = this.est; - hi = this.fence; - } - result = hi; - } - return result; - } - - /** - * [SUBROUTINE] LinkedHashSet_KeySpliteratorAutomaton::_checkForComodification() -> void - * Source: java/util/LinkedHashSet.Spliterator.lsl:79 - */ - private void _checkForComodification() { - /* body */ { - final int modCount = ((LinkedHashSet) ((Object) this.parent)).modCount; - if (this.expectedModCount != modCount) { - throw new ConcurrentModificationException(); - } - } - } - - /** - * [FUNCTION] LinkedHashSet_KeySpliteratorAutomaton::estimateSize(LinkedHashSet_KeySpliterator) -> long - * Source: java/util/LinkedHashSet.Spliterator.lsl:100 - */ - public long estimateSize() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _getFence(); - result = ((long) this.est); - } - return result; - } - - /** - * [FUNCTION] LinkedHashSet_KeySpliteratorAutomaton::characteristics(LinkedHashSet_KeySpliterator) -> int - * Source: java/util/LinkedHashSet.Spliterator.lsl:107 - */ - public int characteristics() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.parent != null); - final LibSLRuntime.Map parentStorage = ((LinkedHashSet) ((Object) this.parent)).storage; - result = 0; - if ((this.fence < 0) || (this.est == parentStorage.size())) { - result = LibSLGlobals.SPLITERATOR_SIZED; - } - result |= LibSLGlobals.SPLITERATOR_DISTINCT; - } - return result; - } - - /** - * [FUNCTION] LinkedHashSet_KeySpliteratorAutomaton::forEachRemaining(LinkedHashSet_KeySpliterator, Consumer) -> void - * Source: java/util/LinkedHashSet.Spliterator.lsl:121 - */ - public void forEachRemaining(Consumer userAction) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.parent != null); - if (userAction == null) { - throw new NullPointerException(); - } - int hi = this.fence; - int mc = this.expectedModCount; - int i = this.index; - final LibSLRuntime.Map parentStorage = ((LinkedHashSet) ((Object) this.parent)).storage; - final int length = parentStorage.size(); - if (hi < 0) { - this.expectedModCount = ((LinkedHashSet) ((Object) this.parent)).modCount; - mc = this.expectedModCount; - this.fence = length; - hi = this.fence; - } - this.index = hi; - if ((length > 0) && (length >= hi) && (i >= 0) && (i < this.index)) { - final Object[] storage = this.keysStorage; - Engine.assume(storage != null); - while (i < hi) { - final Object key = storage[i]; - userAction.accept(key); - i += 1; - } - ; - final int modCount = ((LinkedHashSet) ((Object) this.parent)).modCount; - if (modCount != mc) { - throw new ConcurrentModificationException(); - } - } - } - } - - /** - * [FUNCTION] LinkedHashSet_KeySpliteratorAutomaton::tryAdvance(LinkedHashSet_KeySpliterator, Consumer) -> boolean - * Source: java/util/LinkedHashSet.Spliterator.lsl:168 - */ - public boolean tryAdvance(Consumer userAction) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.parent != null); - if (userAction == null) { - throw new NullPointerException(); - } - int hi = _getFence(); - int i = this.index; - if (i < hi) { - final Object key = keysStorage[i]; - userAction.accept(key); - this.index += 1; - _checkForComodification(); - result = true; - } - result = false; - } - return result; - } - - /** - * [FUNCTION] LinkedHashSet_KeySpliteratorAutomaton::trySplit(LinkedHashSet_KeySpliterator) -> Spliterator - * Source: java/util/LinkedHashSet.Spliterator.lsl:192 - */ - public Spliterator trySplit() { - Spliterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.parent != null); - final int hi = _getFence(); - final int lo = this.index; - int mid = (hi + lo) >>> 1; - if (lo >= mid) { - result = null; - } else { - this.est = this.est >>> 1; - this.index = mid; - result = (stub.java.util.LinkedHashSet_KeySpliterator) ((Object) new LinkedHashSet_KeySpliterator((Void) null, - /* state = */ LinkedHashSet_KeySpliterator.__$lsl_States.Initialized, - /* keysStorage = */ this.keysStorage, - /* index = */ lo, - /* fence = */ mid, - /* est = */ this.est, - /* expectedModCount = */ this.expectedModCount, - /* parent = */ this.parent - )); - } - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(LinkedHashSet_KeySpliterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/LinkedList.java b/approximations/src/main/java/generated/java/util/LinkedList.java deleted file mode 100644 index 44c22137..00000000 --- a/approximations/src/main/java/generated/java/util/LinkedList.java +++ /dev/null @@ -1,1425 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/LinkedList.lsl:19 -// - java/util/LinkedList.main.lsl:18 -// -package generated.java.util; - -import java.io.Serializable; -import java.lang.Cloneable; -import java.lang.Comparable; -import java.lang.IllegalArgumentException; -import java.lang.IndexOutOfBoundsException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Collection; -import java.util.Comparator; -import java.util.ConcurrentModificationException; -import java.util.Deque; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.NoSuchElementException; -import java.util.Spliterator; -import java.util.function.Consumer; -import java.util.function.IntFunction; -import java.util.function.Predicate; -import java.util.function.UnaryOperator; -import java.util.stream.Stream; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import org.usvm.api.SymbolicList; -import runtime.LibSLRuntime; -import stub.java.util.stream.StreamLSL; - -/** - * LinkedListAutomaton for LinkedList ~> java.util.LinkedList - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.util.LinkedList.class) -public class LinkedList implements LibSLRuntime.Automaton, List, Deque, Cloneable, Serializable { - private static final long serialVersionUID = 876323262645176354L; - - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public SymbolicList storage; - - public transient int modCount; - - @LibSLRuntime.AutomatonConstructor - public LinkedList(Void __$lsl_token, final byte p0, final SymbolicList p1, - final int p2) { - this.__$lsl_state = p0; - this.storage = p1; - this.modCount = p2; - } - - @LibSLRuntime.AutomatonConstructor - public LinkedList(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, null, 0); - } - - /** - * [CONSTRUCTOR] LinkedListAutomaton::(LinkedList) -> void - * Source: java/util/LinkedList.main.lsl:566 - */ - public LinkedList() { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.storage = Engine.makeSymbolicList(); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] LinkedListAutomaton::(LinkedList, Collection) -> void - * Source: java/util/LinkedList.main.lsl:572 - */ - public LinkedList(Collection c) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - if (c == null) { - throw new NullPointerException(); - } - this.storage = Engine.makeSymbolicList(); - _addAllElements(this.storage.size(), c); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] LinkedListAutomaton::_checkForComodification(int) -> void - * Source: java/util/LinkedList.main.lsl:109 - */ - public void _checkForComodification(int expectedModCount) { - /* body */ { - if (this.modCount != expectedModCount) { - throw new ConcurrentModificationException(); - } - } - } - - /** - * [SUBROUTINE] LinkedListAutomaton::_subListRangeCheck(int, int, int) -> void - * Source: java/util/LinkedList.main.lsl:117 - */ - public void _subListRangeCheck(int fromIndex, int toIndex, int size) { - /* body */ { - if (fromIndex < 0) { - throw new IndexOutOfBoundsException(); - } - if (toIndex > size) { - throw new IndexOutOfBoundsException(); - } - if (fromIndex > toIndex) { - throw new IllegalArgumentException(); - } - } - } - - /** - * [SUBROUTINE] LinkedListAutomaton::_unlinkAny(int) -> Object - * Source: java/util/LinkedList.main.lsl:141 - */ - public Object _unlinkAny(int index) { - Object result = null; - /* body */ { - result = this.storage.get(index); - this.storage.remove(index); - this.modCount += 1; - } - return result; - } - - /** - * [SUBROUTINE] LinkedListAutomaton::_linkAny(int, Object) -> void - * Source: java/util/LinkedList.main.lsl:149 - */ - public void _linkAny(int index, Object e) { - /* body */ { - this.storage.insert(index, e); - this.modCount += 1; - } - } - - /** - * [SUBROUTINE] LinkedListAutomaton::_checkElementIndex(int, int) -> void - * Source: java/util/LinkedList.main.lsl:156 - */ - public void _checkElementIndex(int index, int size) { - /* body */ { - if (!_isValidIndex(index, size)) { - throw new IndexOutOfBoundsException(); - } - } - } - - /** - * [SUBROUTINE] LinkedListAutomaton::_isValidIndex(int, int) -> boolean - * Source: java/util/LinkedList.main.lsl:168 - */ - private boolean _isValidIndex(int index, int size) { - boolean result = false; - /* body */ { - result = (0 <= index) && (index < size); - } - return result; - } - - /** - * [SUBROUTINE] LinkedListAutomaton::_isPositionIndex(int) -> boolean - * Source: java/util/LinkedList.main.lsl:174 - */ - private boolean _isPositionIndex(int index) { - boolean result = false; - /* body */ { - result = (0 <= index) && (index <= this.storage.size()); - } - return result; - } - - /** - * [SUBROUTINE] LinkedListAutomaton::_checkPositionIndex(int) -> void - * Source: java/util/LinkedList.main.lsl:180 - */ - public void _checkPositionIndex(int index) { - /* body */ { - if (!_isPositionIndex(index)) { - throw new IndexOutOfBoundsException(); - } - } - } - - /** - * [SUBROUTINE] LinkedListAutomaton::_unlinkFirst() -> Object - * Source: java/util/LinkedList.main.lsl:192 - */ - private Object _unlinkFirst() { - Object result = null; - /* body */ { - if (this.storage.size() == 0) { - throw new NoSuchElementException(); - } - result = _unlinkAny(0); - } - return result; - } - - /** - * [SUBROUTINE] LinkedListAutomaton::_unlinkByFirstEqualsObject(Object) -> boolean - * Source: java/util/LinkedList.main.lsl:201 - */ - private boolean _unlinkByFirstEqualsObject(Object o) { - boolean result = false; - /* body */ { - final int index = LibSLRuntime.ListActions.find(this.storage, o, 0, this.storage.size()); - result = index != -1; - if (result) { - this.storage.remove(index); - this.modCount += 1; - } - } - return result; - } - - /** - * [SUBROUTINE] LinkedListAutomaton::_addAllElements(int, Collection) -> boolean - * Source: java/util/LinkedList.main.lsl:213 - */ - public boolean _addAllElements(int index, Collection c) { - boolean result = false; - /* body */ { - _checkPositionIndex(index); - final Iterator iter = c.iterator(); - result = iter.hasNext(); - while (iter.hasNext()) { - final Object item = iter.next(); - this.storage.insert(index, item); - index += 1; - } - ; - this.modCount += 1; - } - return result; - } - - /** - * [SUBROUTINE] LinkedListAutomaton::_getFirstElement() -> Object - * Source: java/util/LinkedList.main.lsl:238 - */ - private Object _getFirstElement() { - Object result = null; - /* body */ { - if (this.storage.size() == 0) { - throw new NoSuchElementException(); - } - result = this.storage.get(0); - } - return result; - } - - /** - * [SUBROUTINE] LinkedListAutomaton::_replaceAllRange(UnaryOperator, int, int) -> void - * Source: java/util/LinkedList.main.lsl:247 - */ - public void _replaceAllRange(UnaryOperator op, int i, int end) { - /* body */ { - final int expectedModCount = this.modCount; - while ((this.modCount == expectedModCount) && (i < end)) { - final Object oldItem = this.storage.get(i); - final Object newItem = op.apply(oldItem); - this.storage.set(i, newItem); - i += 1; - } - ; - _checkForComodification(expectedModCount); - } - } - - /** - * [SUBROUTINE] LinkedListAutomaton::_removeIf(Predicate, int, int) -> boolean - * Source: java/util/LinkedList.main.lsl:269 - */ - public boolean _removeIf(Predicate filter, int start, int end) { - boolean result = false; - /* body */ { - if (filter == null) { - throw new NullPointerException(); - } - final int oldSize = this.storage.size(); - final int expectedModCount = this.modCount; - Engine.assume(start <= end); - int i = 0; - for (i = end - 1; i > start; i += -1) { - final Object item = this.storage.get(i); - if (filter.test(item)) { - this.storage.remove(i); - } - } - ; - _checkForComodification(expectedModCount); - result = oldSize != this.storage.size(); - } - return result; - } - - /** - * [SUBROUTINE] LinkedListAutomaton::_equalsRange(List, int, int) -> boolean - * Source: java/util/LinkedList.main.lsl:299 - */ - public boolean _equalsRange(List other, int from, int to) { - boolean result = false; - /* body */ { - result = true; - int i = from; - int otherLength = 0; - SymbolicList otherStorage = null; - if ((other != null && other.getClass() == java.util.LinkedList.class)) { - otherStorage = ((LinkedList) ((Object) other)).storage; - otherLength = otherStorage.size(); - result = to == otherLength; - if (result) { - while (result && (i < to)) { - final Object a = otherStorage.get(i); - final Object b = this.storage.get(i); - result = LibSLRuntime.equals(a, b); - i += 1; - } - ; - } - } else { - final Iterator iter = other.iterator(); - while (result && (i < to) && iter.hasNext()) { - final Object a = iter.next(); - final Object b = this.storage.get(i); - result = LibSLRuntime.equals(a, b); - i += 1; - } - ; - result &= !iter.hasNext(); - } - } - return result; - } - - /** - * [SUBROUTINE] LinkedListAutomaton::_makeStream(boolean) -> Stream - * Source: java/util/LinkedList.main.lsl:374 - */ - private Stream _makeStream(boolean parallel) { - Stream result = null; - /* body */ { - final int count = this.storage.size(); - final Object[] items = new Object[count]; - int i = 0; - for (i = 0; i < count; i += 1) { - items[i] = this.storage.get(i); - } - ; - result = (StreamLSL) ((Object) new generated.java.util.stream.StreamLSL((Void) null, - /* state = */ generated.java.util.stream.StreamLSL.__$lsl_States.Initialized, - /* storage = */ items, - /* length = */ count, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ parallel, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [SUBROUTINE] LinkedListAutomaton::_batchRemove(Collection, boolean, int, int) -> boolean - * Source: java/util/LinkedList.main.lsl:401 - */ - public boolean _batchRemove(Collection c, boolean complement, int start, int end) { - boolean result = false; - /* body */ { - if (c == null) { - throw new NullPointerException(); - } - final int oldSize = this.storage.size(); - if ((oldSize == 0) || (start >= end)) { - result = false; - } else { - final int otherLength = c.size(); - if (otherLength == 0) { - if (complement) { - result = true; - this.storage = Engine.makeSymbolicList(); - this.modCount += 1; - } else { - result = false; - } - } else { - Engine.assume(otherLength > 0); - int i = 0; - start -= 1; - end -= 1; - if ((c != null && c.getClass() == java.util.LinkedList.class)) { - final SymbolicList otherStorage = ((LinkedList) ((Object) c)).storage; - Engine.assume(otherStorage != null); - for (i = end; i > start; i += -1) { - final Object item = this.storage.get(i); - if ((LibSLRuntime.ListActions.find(otherStorage, item, 0, this.storage.size()) == -1) == complement) { - _unlinkAny(i); - } - } - ; - } else { - for (i = end; i > start; i += -1) { - final Object item = this.storage.get(i); - if (c.contains(item) != complement) { - _unlinkAny(i); - } - } - ; - } - result = oldSize != this.storage.size(); - } - } - } - return result; - } - - /** - * [SUBROUTINE] LinkedListAutomaton::_do_sort(int, int, Comparator) -> void - * Source: java/util/LinkedList.main.lsl:473 - */ - public void _do_sort(int start, int end, Comparator c) { - /* body */ { - if (start < end) { - final int expectedModCount = this.modCount; - Engine.assume(start >= 0); - Engine.assume(end > 0); - final int outerLimit = end - 1; - int innerLimit = 0; - int i = 0; - int j = 0; - if (c == null) { - for (i = start; i < outerLimit; i += 1) { - innerLimit = (end - i) - 1; - for (j = start; j < innerLimit; j += 1) { - final int idxA = j; - final int idxB = j + 1; - final Object a = this.storage.get(idxA); - final Object b = this.storage.get(idxB); - if (((Comparable) a).compareTo(b) > 0) { - this.storage.set(idxA, b); - this.storage.set(idxB, a); - } - } - ; - } - ; - } else { - for (i = start; i < outerLimit; i += 1) { - innerLimit = (end - i) - 1; - for (j = start; j < innerLimit; j += 1) { - final int idxA = j; - final int idxB = j + 1; - final Object a = this.storage.get(idxA); - final Object b = this.storage.get(idxB); - if (c.compare(a, b) > 0) { - this.storage.set(idxA, b); - this.storage.set(idxB, a); - } - } - ; - } - ; - } - _checkForComodification(expectedModCount); - } - this.modCount += 1; - } - } - - /** - * [FUNCTION] LinkedListAutomaton::add(LinkedList, Object) -> boolean - * Source: java/util/LinkedList.main.lsl:585 - */ - public boolean add(Object e) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _linkAny(this.storage.size(), e); - result = true; - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::add(LinkedList, int, Object) -> void - * Source: java/util/LinkedList.main.lsl:592 - */ - public void add(int index, Object element) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _checkPositionIndex(index); - _linkAny(index, element); - } - } - - /** - * [FUNCTION] LinkedListAutomaton::addAll(LinkedList, Collection) -> boolean - * Source: java/util/LinkedList.main.lsl:599 - */ - public boolean addAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _addAllElements(this.storage.size(), c); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::addAll(LinkedList, int, Collection) -> boolean - * Source: java/util/LinkedList.main.lsl:605 - */ - public boolean addAll(int index, Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _addAllElements(index, c); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::addFirst(LinkedList, Object) -> void - * Source: java/util/LinkedList.main.lsl:611 - */ - public void addFirst(Object e) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _linkAny(0, e); - } - } - - /** - * [FUNCTION] LinkedListAutomaton::addLast(LinkedList, Object) -> void - * Source: java/util/LinkedList.main.lsl:617 - */ - public void addLast(Object e) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _linkAny(this.storage.size(), e); - } - } - - /** - * [FUNCTION] LinkedListAutomaton::clear(LinkedList) -> void - * Source: java/util/LinkedList.main.lsl:623 - */ - public void clear() { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.storage = Engine.makeSymbolicList(); - this.modCount += 1; - } - } - - /** - * [FUNCTION] LinkedListAutomaton::clone(LinkedList) -> Object - * Source: java/util/LinkedList.main.lsl:630 - */ - public Object clone() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final SymbolicList storageCopy = Engine.makeSymbolicList(); - this.storage.copy(storageCopy, 0, 0, this.storage.size()); - result = (java.util.LinkedList) ((Object) new LinkedList((Void) null, - /* state = */ LinkedList.__$lsl_States.Initialized, - /* storage = */ storageCopy, - /* modCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::contains(LinkedList, Object) -> boolean - * Source: java/util/LinkedList.main.lsl:641 - */ - public boolean contains(Object o) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = LibSLRuntime.ListActions.find(this.storage, o, 0, this.storage.size()) != -1; - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::containsAll(LinkedList, Collection) -> boolean - * Source: java/util/LinkedList.main.lsl:648 - */ - public boolean containsAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = true; - if ((c != null && c.getClass() == java.util.LinkedList.class)) { - final SymbolicList otherStorage = ((LinkedList) ((Object) c)).storage; - final int otherSize = otherStorage.size(); - Engine.assume(otherStorage != null); - Engine.assume(otherSize >= 0); - int i = 0; - while (result && (i < otherSize)) { - final Object item = otherStorage.get(i); - result = LibSLRuntime.ListActions.find(this.storage, item, 0, this.storage.size()) != -1; - i += 1; - } - ; - } else { - final Iterator iter = c.iterator(); - while (result && iter.hasNext()) { - final Object item = iter.next(); - result = LibSLRuntime.ListActions.find(this.storage, item, 0, this.storage.size()) != -1; - } - ; - } - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::descendingIterator(LinkedList) -> Iterator - * Source: java/util/LinkedList.main.lsl:691 - */ - public Iterator descendingIterator() { - Iterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (stub.java.util.LinkedList_DescendingIterator) ((Object) new LinkedList_DescendingIterator((Void) null, - /* state = */ LinkedList_DescendingIterator.__$lsl_States.Initialized, - /* parent = */ this, - /* cursor = */ this.storage.size(), - /* expectedModCount = */ this.modCount, - /* lastRet = */ -1 - )); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::element(LinkedList) -> Object - * Source: java/util/LinkedList.main.lsl:701 - */ - public Object element() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _getFirstElement(); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::equals(LinkedList, Object) -> boolean - * Source: java/util/LinkedList.main.lsl:708 - */ - public boolean equals(Object o) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this == o) { - result = true; - } else { - if ((o != null && o.getClass() == java.util.LinkedList.class)) { - final int expectedModCount = this.modCount; - final int otherExpectedModCount = ((LinkedList) ((Object) o)).modCount; - final SymbolicList otherStorage = ((LinkedList) ((Object) o)).storage; - if (this.storage.size() == otherStorage.size()) { - result = LibSLRuntime.equals(this.storage, otherStorage); - } else { - result = false; - } - ((LinkedList) ((Object) o))._checkForComodification(otherExpectedModCount); - _checkForComodification(expectedModCount); - } else { - result = false; - } - } - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::forEach(LinkedList, Consumer) -> void - * Source: java/util/LinkedList.main.lsl:744 - */ - public void forEach(Consumer _action) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - final int expectedModCount = this.modCount; - int i = 0; - while ((this.modCount == expectedModCount) && (i < this.storage.size())) { - final Object item = this.storage.get(i); - _action.accept(item); - i += 1; - } - ; - _checkForComodification(expectedModCount); - } - } - - /** - * [FUNCTION] LinkedListAutomaton::get(LinkedList, int) -> Object - * Source: java/util/LinkedList.main.lsl:769 - */ - public Object get(int index) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _checkElementIndex(index, this.storage.size()); - result = this.storage.get(index); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::getFirst(LinkedList) -> Object - * Source: java/util/LinkedList.main.lsl:776 - */ - public Object getFirst() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _getFirstElement(); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::getLast(LinkedList) -> Object - * Source: java/util/LinkedList.main.lsl:782 - */ - public Object getLast() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.storage.size() == 0) { - throw new NoSuchElementException(); - } - result = this.storage.get(this.storage.size() - 1); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::hashCode(LinkedList) -> int - * Source: java/util/LinkedList.main.lsl:792 - */ - public int hashCode() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = LibSLRuntime.hashCode(this.storage); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::indexOf(LinkedList, Object) -> int - * Source: java/util/LinkedList.main.lsl:798 - */ - public int indexOf(Object o) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = LibSLRuntime.ListActions.find(this.storage, o, 0, this.storage.size()); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::isEmpty(LinkedList) -> boolean - * Source: java/util/LinkedList.main.lsl:805 - */ - public boolean isEmpty() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.storage.size() == 0; - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::iterator(LinkedList) -> Iterator - * Source: java/util/LinkedList.main.lsl:812 - */ - public Iterator iterator() { - Iterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (stub.java.util.LinkedList_ListItr) ((Object) new LinkedList_ListItr((Void) null, - /* state = */ LinkedList_ListItr.__$lsl_States.Initialized, - /* parent = */ this, - /* cursor = */ 0, - /* expectedModCount = */ this.modCount, - /* lastRet = */ -1 - )); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::lastIndexOf(LinkedList, Object) -> int - * Source: java/util/LinkedList.main.lsl:822 - */ - public int lastIndexOf(Object o) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = -1; - final int size = this.storage.size(); - if (size != 0) { - Engine.assume(size > 0); - final SymbolicList items = this.storage; - int i = 0; - for (i = size - 1; i > -1; i += -1) { - final Object e = items.get(i); - if (LibSLRuntime.equals(o, e)) { - result = i; - break; - } - } - ; - } - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::listIterator(LinkedList) -> ListIterator - * Source: java/util/LinkedList.main.lsl:854 - */ - public ListIterator listIterator() { - ListIterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (stub.java.util.LinkedList_ListItr) ((Object) new LinkedList_ListItr((Void) null, - /* state = */ LinkedList_ListItr.__$lsl_States.Initialized, - /* parent = */ this, - /* cursor = */ 0, - /* expectedModCount = */ this.modCount, - /* lastRet = */ -1 - )); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::listIterator(LinkedList, int) -> ListIterator - * Source: java/util/LinkedList.main.lsl:864 - */ - public ListIterator listIterator(int index) { - ListIterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _checkPositionIndex(index); - result = (stub.java.util.LinkedList_ListItr) ((Object) new LinkedList_ListItr((Void) null, - /* state = */ LinkedList_ListItr.__$lsl_States.Initialized, - /* parent = */ this, - /* cursor = */ index, - /* expectedModCount = */ this.modCount, - /* lastRet = */ -1 - )); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::offer(LinkedList, Object) -> boolean - * Source: java/util/LinkedList.main.lsl:876 - */ - public boolean offer(Object e) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _linkAny(this.storage.size(), e); - result = true; - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::offerFirst(LinkedList, Object) -> boolean - * Source: java/util/LinkedList.main.lsl:883 - */ - public boolean offerFirst(Object e) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _linkAny(0, e); - result = true; - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::offerLast(LinkedList, Object) -> boolean - * Source: java/util/LinkedList.main.lsl:890 - */ - public boolean offerLast(Object e) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _linkAny(this.storage.size(), e); - result = true; - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::parallelStream(LinkedList) -> Stream - * Source: java/util/LinkedList.main.lsl:898 - */ - public Stream parallelStream() { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _makeStream(true); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::peek(LinkedList) -> Object - * Source: java/util/LinkedList.main.lsl:904 - */ - public Object peek() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.storage.size() == 0) { - result = null; - } else { - result = this.storage.get(0); - } - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::peekFirst(LinkedList) -> Object - * Source: java/util/LinkedList.main.lsl:913 - */ - public Object peekFirst() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.storage.size() == 0) { - result = null; - } else { - result = this.storage.get(0); - } - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::peekLast(LinkedList) -> Object - * Source: java/util/LinkedList.main.lsl:922 - */ - public Object peekLast() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.storage.size() == 0) { - result = null; - } else { - result = this.storage.get(this.storage.size() - 1); - } - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::poll(LinkedList) -> Object - * Source: java/util/LinkedList.main.lsl:931 - */ - public Object poll() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.storage.size() == 0) { - result = null; - } else { - result = _unlinkAny(0); - } - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::pollFirst(LinkedList) -> Object - * Source: java/util/LinkedList.main.lsl:940 - */ - public Object pollFirst() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.storage.size() == 0) { - result = null; - } else { - result = _unlinkAny(0); - } - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::pollLast(LinkedList) -> Object - * Source: java/util/LinkedList.main.lsl:949 - */ - public Object pollLast() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.storage.size() == 0) { - result = null; - } else { - result = _unlinkAny(this.storage.size() - 1); - } - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::pop(LinkedList) -> Object - * Source: java/util/LinkedList.main.lsl:958 - */ - public Object pop() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _unlinkFirst(); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::push(LinkedList, Object) -> void - * Source: java/util/LinkedList.main.lsl:964 - */ - public void push(Object e) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _linkAny(0, e); - } - } - - /** - * [FUNCTION] LinkedListAutomaton::remove(LinkedList) -> Object - * Source: java/util/LinkedList.main.lsl:970 - */ - public Object remove() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _unlinkFirst(); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::remove(LinkedList, Object) -> boolean - * Source: java/util/LinkedList.main.lsl:976 - */ - public boolean remove(Object o) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _unlinkByFirstEqualsObject(o); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::remove(LinkedList, int) -> Object - * Source: java/util/LinkedList.main.lsl:982 - */ - public Object remove(int index) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _checkElementIndex(index, this.storage.size()); - result = _unlinkAny(index); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::removeAll(LinkedList, Collection) -> boolean - * Source: java/util/LinkedList.main.lsl:990 - */ - public boolean removeAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _batchRemove(c, false, 0, this.storage.size()); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::removeFirst(LinkedList) -> Object - * Source: java/util/LinkedList.main.lsl:996 - */ - public Object removeFirst() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _unlinkFirst(); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::removeFirstOccurrence(LinkedList, Object) -> boolean - * Source: java/util/LinkedList.main.lsl:1002 - */ - public boolean removeFirstOccurrence(Object o) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _unlinkByFirstEqualsObject(o); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::removeIf(LinkedList, Predicate) -> boolean - * Source: java/util/LinkedList.main.lsl:1009 - */ - public boolean removeIf(Predicate filter) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _removeIf(filter, 0, this.storage.size()); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::removeLast(LinkedList) -> Object - * Source: java/util/LinkedList.main.lsl:1015 - */ - public Object removeLast() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.storage.size() == 0) { - throw new NoSuchElementException(); - } - result = _unlinkAny(this.storage.size() - 1); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::removeLastOccurrence(LinkedList, Object) -> boolean - * Source: java/util/LinkedList.main.lsl:1024 - */ - public boolean removeLastOccurrence(Object o) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int size = this.storage.size(); - if (size == 0) { - result = false; - } else { - Engine.assume(size > 0); - int index = size - 1; - for (index = index; index > -1; index += -1) { - final Object item = this.storage.get(index); - if (LibSLRuntime.equals(item, o)) { - break; - } - } - ; - result = index != -1; - if (result) { - this.storage.remove(index); - this.modCount += 1; - } - } - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::replaceAll(LinkedList, UnaryOperator) -> void - * Source: java/util/LinkedList.main.lsl:1061 - */ - public void replaceAll(UnaryOperator op) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (op == null) { - throw new NullPointerException(); - } - _replaceAllRange(op, 0, this.storage.size()); - this.modCount += 1; - } - } - - /** - * [FUNCTION] LinkedListAutomaton::retainAll(LinkedList, Collection) -> boolean - * Source: java/util/LinkedList.main.lsl:1072 - */ - public boolean retainAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _batchRemove(c, true, 0, this.storage.size()); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::set(LinkedList, int, Object) -> Object - * Source: java/util/LinkedList.main.lsl:1078 - */ - public Object set(int index, Object element) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _checkElementIndex(index, this.storage.size()); - result = this.storage.get(index); - this.storage.set(index, element); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::size(LinkedList) -> int - * Source: java/util/LinkedList.main.lsl:1086 - */ - public int size() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.storage.size(); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::sort(LinkedList, Comparator) -> void - * Source: java/util/LinkedList.main.lsl:1093 - */ - public void sort(Comparator c) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _do_sort(0, this.storage.size(), c); - } - } - - /** - * [FUNCTION] LinkedListAutomaton::spliterator(LinkedList) -> Spliterator - * Source: java/util/LinkedList.main.lsl:1099 - */ - public Spliterator spliterator() { - Spliterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (stub.java.util.LinkedList_Spliterator) ((Object) new LinkedList_Spliterator((Void) null, - /* state = */ LinkedList_Spliterator.__$lsl_States.Initialized, - /* parent = */ this, - /* index = */ 0, - /* fence = */ -1, - /* expectedModCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::stream(LinkedList) -> Stream - * Source: java/util/LinkedList.main.lsl:1108 - */ - public Stream stream() { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _makeStream(false); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::subList(LinkedList, int, int) -> List - * Source: java/util/LinkedList.main.lsl:1115 - */ - public List subList(int fromIndex, int toIndex) { - List result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _subListRangeCheck(fromIndex, toIndex, this.storage.size()); - result = (stub.java.util.LinkedList_SubList) ((Object) new LinkedList_SubList((Void) null, - /* state = */ LinkedList_SubList.__$lsl_States.Initialized, - /* root = */ this, - /* parentList = */ null, - /* offset = */ fromIndex, - /* length = */ toIndex - fromIndex, - /* modCount = */ this.modCount - )); - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::toArray(LinkedList) -> array - * Source: java/util/LinkedList.main.lsl:1129 - */ - public Object[] toArray() { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int len = this.storage.size(); - result = new Object[len]; - int i = 0; - for (i = 0; i < len; i += 1) { - result[i] = this.storage.get(i); - } - ; - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::toArray(LinkedList, IntFunction) -> array - * Source: java/util/LinkedList.main.lsl:1149 - */ - public Object[] toArray(IntFunction generator) { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final Object[] a = ((Object[]) generator.apply(0)); - final int aLen = a.length; - final int len = this.storage.size(); - result = new Object[len]; - int i = 0; - for (i = 0; i < len; i += 1) { - result[i] = this.storage.get(i); - } - ; - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::toArray(LinkedList, array) -> array - * Source: java/util/LinkedList.main.lsl:1167 - */ - public Object[] toArray(Object[] a) { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int aLen = a.length; - final int len = this.storage.size(); - int i = 0; - if (aLen < len) { - result = new Object[len]; - for (i = 0; i < len; i += 1) { - result[i] = this.storage.get(i); - } - ; - } else { - result = a; - for (i = 0; i < len; i += 1) { - result[i] = this.storage.get(i); - } - ; - if (aLen > len) { - result[len] = null; - } - } - } - return result; - } - - /** - * [FUNCTION] LinkedListAutomaton::toString(LinkedList) -> String - * Source: java/util/LinkedList.main.lsl:1199 - */ - public String toString() { - String result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = LibSLRuntime.toString(this.storage); - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(LinkedList.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/LinkedList_DescendingIterator.java b/approximations/src/main/java/generated/java/util/LinkedList_DescendingIterator.java deleted file mode 100644 index 2a418da2..00000000 --- a/approximations/src/main/java/generated/java/util/LinkedList_DescendingIterator.java +++ /dev/null @@ -1,158 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/LinkedList.lsl:43 -// - java/util/LinkedList.DescendingIterator.lsl:18 -// -package generated.java.util; - -import java.lang.IllegalStateException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ConcurrentModificationException; -import java.util.Iterator; -import java.util.NoSuchElementException; -import java.util.function.Consumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import org.usvm.api.SymbolicList; -import runtime.LibSLRuntime; - -/** - * LinkedList_DescendingIteratorAutomaton for LinkedList_DescendingIterator ~> java.util.LinkedList_DescendingIterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.LinkedList_DescendingIterator.class) -public final class LinkedList_DescendingIterator implements LibSLRuntime.Automaton, Iterator { - static { - Engine.assume(true); - } - - public LinkedList parent; - - public int cursor; - - public int expectedModCount; - - public int lastRet; - - @LibSLRuntime.AutomatonConstructor - public LinkedList_DescendingIterator(Void __$lsl_token, final byte p0, final LinkedList p1, - final int p2, final int p3, final int p4) { - this.parent = p1; - this.cursor = p2; - this.expectedModCount = p3; - this.lastRet = p4; - } - - @LibSLRuntime.AutomatonConstructor - public LinkedList_DescendingIterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, 0, 0, -1); - } - - /** - * [FUNCTION] LinkedList_DescendingIteratorAutomaton::hasNext(LinkedList_DescendingIterator) -> boolean - * Source: java/util/LinkedList.DescendingIterator.lsl:60 - */ - public boolean hasNext() { - boolean result = false; - /* body */ { - Engine.assume(this.parent != null); - result = this.cursor != 0; - } - return result; - } - - /** - * [FUNCTION] LinkedList_DescendingIteratorAutomaton::next(LinkedList_DescendingIterator) -> Object - * Source: java/util/LinkedList.DescendingIterator.lsl:69 - */ - public Object next() { - Object result = null; - /* body */ { - Engine.assume(this.parent != null); - if (((LinkedList) ((Object) this.parent)).modCount != this.expectedModCount) { - throw new ConcurrentModificationException(); - } - final SymbolicList parentStorage = ((LinkedList) ((Object) this.parent)).storage; - final int i = this.cursor - 1; - if (i < 0) { - throw new NoSuchElementException(); - } - if (i >= parentStorage.size()) { - throw new ConcurrentModificationException(); - } - this.cursor = i; - this.lastRet = i; - result = parentStorage.get(i); - } - return result; - } - - /** - * [FUNCTION] LinkedList_DescendingIteratorAutomaton::remove(LinkedList_DescendingIterator) -> void - * Source: java/util/LinkedList.DescendingIterator.lsl:93 - */ - public void remove() { - /* body */ { - Engine.assume(this.parent != null); - if (this.lastRet < 0) { - throw new IllegalStateException(); - } - if (((LinkedList) ((Object) this.parent)).modCount != this.expectedModCount) { - throw new ConcurrentModificationException(); - } - final SymbolicList pStorage = ((LinkedList) ((Object) this.parent)).storage; - if (this.lastRet >= pStorage.size()) { - throw new ConcurrentModificationException(); - } else { - ((LinkedList) ((Object) this.parent)).modCount += 1; - pStorage.remove(this.lastRet); - } - this.cursor = this.lastRet; - this.lastRet = -1; - this.expectedModCount = ((LinkedList) ((Object) this.parent)).modCount; - } - } - - /** - * [FUNCTION] LinkedList_DescendingIteratorAutomaton::forEachRemaining(LinkedList_DescendingIterator, Consumer) -> void - * Source: java/util/LinkedList.DescendingIterator.lsl:121 - */ - public void forEachRemaining(Consumer userAction) { - /* body */ { - Engine.assume(this.parent != null); - if (userAction == null) { - throw new NullPointerException(); - } - int i = this.cursor; - final SymbolicList es = ((LinkedList) ((Object) this.parent)).storage; - final int size = es.size(); - if (i < size) { - while ((i < size) && (((LinkedList) ((Object) this.parent)).modCount == this.expectedModCount)) { - final Object item = es.get(i); - userAction.accept(item); - i += 1; - } - ; - this.cursor = i; - this.lastRet = i - 1; - if (((LinkedList) ((Object) this.parent)).modCount != this.expectedModCount) { - throw new ConcurrentModificationException(); - } - } - } - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(LinkedList_DescendingIterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/LinkedList_ListItr.java b/approximations/src/main/java/generated/java/util/LinkedList_ListItr.java deleted file mode 100644 index 6a42b636..00000000 --- a/approximations/src/main/java/generated/java/util/LinkedList_ListItr.java +++ /dev/null @@ -1,264 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/LinkedList.lsl:34 -// - java/util/LinkedList.ListIterator.lsl:16 -// -package generated.java.util; - -import java.lang.IllegalStateException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ConcurrentModificationException; -import java.util.ListIterator; -import java.util.NoSuchElementException; -import java.util.function.Consumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import org.usvm.api.SymbolicList; -import runtime.LibSLRuntime; - -/** - * LinkedList_ListIteratorAutomaton for LinkedList_ListIterator ~> java.util.LinkedList_ListItr - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.LinkedList_ListItr.class) -public final class LinkedList_ListItr implements LibSLRuntime.Automaton, ListIterator { - static { - Engine.assume(true); - } - - public LinkedList parent; - - public int cursor; - - public int expectedModCount; - - public int lastRet; - - @LibSLRuntime.AutomatonConstructor - public LinkedList_ListItr(Void __$lsl_token, final byte p0, final LinkedList p1, final int p2, - final int p3, final int p4) { - this.parent = p1; - this.cursor = p2; - this.expectedModCount = p3; - this.lastRet = p4; - } - - @LibSLRuntime.AutomatonConstructor - public LinkedList_ListItr(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, 0, 0, -1); - } - - /** - * [SUBROUTINE] LinkedList_ListIteratorAutomaton::_checkForComodification() -> void - * Source: java/util/LinkedList.ListIterator.lsl:55 - */ - private void _checkForComodification() { - /* body */ { - final int modCount = ((LinkedList) ((Object) this.parent)).modCount; - if (modCount != this.expectedModCount) { - throw new ConcurrentModificationException(); - } - } - } - - /** - * [FUNCTION] LinkedList_ListIteratorAutomaton::hasPrevious(LinkedList_ListIterator) -> boolean - * Source: java/util/LinkedList.ListIterator.lsl:65 - */ - public boolean hasPrevious() { - boolean result = false; - /* body */ { - result = this.cursor != 0; - } - return result; - } - - /** - * [FUNCTION] LinkedList_ListIteratorAutomaton::nextIndex(LinkedList_ListIterator) -> int - * Source: java/util/LinkedList.ListIterator.lsl:71 - */ - public int nextIndex() { - int result = 0; - /* body */ { - result = this.cursor; - } - return result; - } - - /** - * [FUNCTION] LinkedList_ListIteratorAutomaton::previousIndex(LinkedList_ListIterator) -> int - * Source: java/util/LinkedList.ListIterator.lsl:77 - */ - public int previousIndex() { - int result = 0; - /* body */ { - result = this.cursor - 1; - } - return result; - } - - /** - * [FUNCTION] LinkedList_ListIteratorAutomaton::hasNext(LinkedList_ListIterator) -> boolean - * Source: java/util/LinkedList.ListIterator.lsl:83 - */ - public boolean hasNext() { - boolean result = false; - /* body */ { - Engine.assume(this.parent != null); - result = this.cursor != ((LinkedList) ((Object) this.parent)).storage.size(); - } - return result; - } - - /** - * [FUNCTION] LinkedList_ListIteratorAutomaton::next(LinkedList_ListIterator) -> Object - * Source: java/util/LinkedList.ListIterator.lsl:92 - */ - public Object next() { - Object result = null; - /* body */ { - Engine.assume(this.parent != null); - _checkForComodification(); - final SymbolicList parentStorage = ((LinkedList) ((Object) this.parent)).storage; - final int i = this.cursor; - if (i >= parentStorage.size()) { - throw new NoSuchElementException(); - } - this.cursor = i + 1; - this.lastRet = i; - result = parentStorage.get(i); - } - return result; - } - - /** - * [FUNCTION] LinkedList_ListIteratorAutomaton::previous(LinkedList_ListIterator) -> Object - * Source: java/util/LinkedList.ListIterator.lsl:112 - */ - public Object previous() { - Object result = null; - /* body */ { - Engine.assume(this.parent != null); - _checkForComodification(); - final SymbolicList parentStorage = ((LinkedList) ((Object) this.parent)).storage; - final int i = this.cursor - 1; - if (i < 0) { - throw new NoSuchElementException(); - } - if (i >= parentStorage.size()) { - throw new ConcurrentModificationException(); - } - this.cursor = i; - this.lastRet = i; - result = parentStorage.get(i); - } - return result; - } - - /** - * [FUNCTION] LinkedList_ListIteratorAutomaton::remove(LinkedList_ListIterator) -> void - * Source: java/util/LinkedList.ListIterator.lsl:136 - */ - public void remove() { - /* body */ { - Engine.assume(this.parent != null); - if (this.lastRet < 0) { - throw new IllegalStateException(); - } - _checkForComodification(); - final SymbolicList pStorage = ((LinkedList) ((Object) this.parent)).storage; - if (this.lastRet >= pStorage.size()) { - throw new ConcurrentModificationException(); - } else { - ((LinkedList) ((Object) this.parent)).modCount += 1; - pStorage.remove(this.lastRet); - } - this.cursor = this.lastRet; - this.lastRet = -1; - this.expectedModCount = ((LinkedList) ((Object) this.parent)).modCount; - } - } - - /** - * [FUNCTION] LinkedList_ListIteratorAutomaton::set(LinkedList_ListIterator, Object) -> void - * Source: java/util/LinkedList.ListIterator.lsl:164 - */ - public void set(Object e) { - /* body */ { - Engine.assume(this.parent != null); - if (this.lastRet < 0) { - throw new IllegalStateException(); - } - _checkForComodification(); - final SymbolicList pStorage = ((LinkedList) ((Object) this.parent)).storage; - if (this.lastRet >= pStorage.size()) { - throw new ConcurrentModificationException(); - } else { - pStorage.set(this.lastRet, e); - } - } - } - - /** - * [FUNCTION] LinkedList_ListIteratorAutomaton::add(LinkedList_ListIterator, Object) -> void - * Source: java/util/LinkedList.ListIterator.lsl:182 - */ - public void add(Object e) { - /* body */ { - Engine.assume(this.parent != null); - _checkForComodification(); - final int i = this.cursor; - final SymbolicList pStorage = ((LinkedList) ((Object) this.parent)).storage; - if (this.lastRet > pStorage.size()) { - throw new ConcurrentModificationException(); - } else { - ((LinkedList) ((Object) this.parent)).modCount += 1; - pStorage.insert(i, e); - } - this.cursor = i + 1; - this.lastRet = -1; - this.expectedModCount = ((LinkedList) ((Object) this.parent)).modCount; - } - } - - /** - * [FUNCTION] LinkedList_ListIteratorAutomaton::forEachRemaining(LinkedList_ListIterator, Consumer) -> void - * Source: java/util/LinkedList.ListIterator.lsl:209 - */ - public void forEachRemaining(Consumer userAction) { - /* body */ { - Engine.assume(this.parent != null); - if (userAction == null) { - throw new NullPointerException(); - } - int i = this.cursor; - final SymbolicList es = ((LinkedList) ((Object) this.parent)).storage; - final int size = es.size(); - if (i < size) { - while ((i < size) && (((LinkedList) ((Object) this.parent)).modCount == this.expectedModCount)) { - final Object item = es.get(i); - userAction.accept(item); - i += 1; - } - ; - this.cursor = i; - this.lastRet = i - 1; - _checkForComodification(); - } - } - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(LinkedList_ListItr.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/LinkedList_Spliterator.java b/approximations/src/main/java/generated/java/util/LinkedList_Spliterator.java deleted file mode 100644 index f57dfe03..00000000 --- a/approximations/src/main/java/generated/java/util/LinkedList_Spliterator.java +++ /dev/null @@ -1,231 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/LinkedList.lsl:52 -// - java/util/LinkedList.Spliterator.lsl:16 -// -package generated.java.util; - -import generated.runtime.LibSLGlobals; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ConcurrentModificationException; -import java.util.Spliterator; -import java.util.function.Consumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import org.usvm.api.SymbolicList; -import runtime.LibSLRuntime; - -/** - * LinkedList_SpliteratorAutomaton for LinkedList_Spliterator ~> java.util.LinkedList_Spliterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.LinkedList_Spliterator.class) -public final class LinkedList_Spliterator implements LibSLRuntime.Automaton, Spliterator { - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public LinkedList parent; - - public int index; - - public int fence; - - public int expectedModCount; - - @LibSLRuntime.AutomatonConstructor - public LinkedList_Spliterator(Void __$lsl_token, final byte p0, final LinkedList p1, - final int p2, final int p3, final int p4) { - this.__$lsl_state = p0; - this.parent = p1; - this.index = p2; - this.fence = p3; - this.expectedModCount = p4; - } - - @LibSLRuntime.AutomatonConstructor - public LinkedList_Spliterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, null, 0, -1, 0); - } - - /** - * [CONSTRUCTOR] LinkedList_SpliteratorAutomaton::(LinkedList_Spliterator, LinkedList, int, int, int) -> void - * Source: java/util/LinkedList.Spliterator.lsl:81 - */ - private LinkedList_Spliterator(LinkedList _this, int origin, int fence, int expectedModCount) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - LibSLRuntime.not_implemented(/* inaccessible constructor */); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] LinkedList_SpliteratorAutomaton::_getFence() -> int - * Source: java/util/LinkedList.Spliterator.lsl:65 - */ - private int _getFence() { - int result = 0; - /* body */ { - if (this.fence == -1) { - Engine.assume(this.parent != null); - this.expectedModCount = ((LinkedList) ((Object) this.parent)).modCount; - this.fence = ((LinkedList) ((Object) this.parent)).storage.size(); - } - result = this.fence; - } - return result; - } - - /** - * [FUNCTION] LinkedList_SpliteratorAutomaton::characteristics(LinkedList_Spliterator) -> int - * Source: java/util/LinkedList.Spliterator.lsl:94 - */ - public int characteristics() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = LibSLGlobals.SPLITERATOR_ORDERED | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED; - } - return result; - } - - /** - * [FUNCTION] LinkedList_SpliteratorAutomaton::estimateSize(LinkedList_Spliterator) -> long - * Source: java/util/LinkedList.Spliterator.lsl:100 - */ - public long estimateSize() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _getFence() - this.index; - } - return result; - } - - /** - * [FUNCTION] LinkedList_SpliteratorAutomaton::forEachRemaining(LinkedList_Spliterator, Consumer) -> void - * Source: java/util/LinkedList.Spliterator.lsl:106 - */ - public void forEachRemaining(Consumer _action) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - Engine.assume(this.parent != null); - final SymbolicList a = ((LinkedList) ((Object) this.parent)).storage; - if (a == null) { - throw new ConcurrentModificationException(); - } - int hi = this.fence; - int mc = this.expectedModCount; - if (hi == -1) { - hi = a.size(); - mc = ((LinkedList) ((Object) this.parent)).modCount; - } - int i = this.index; - this.index = hi; - if ((i < 0) || (hi > a.size())) { - throw new ConcurrentModificationException(); - } - for (i = i; i < hi; i += 1) { - final Object item = a.get(i); - _action.accept(item); - } - ; - if (mc != ((LinkedList) ((Object) this.parent)).modCount) { - throw new ConcurrentModificationException(); - } - } - } - - /** - * [FUNCTION] LinkedList_SpliteratorAutomaton::getExactSizeIfKnown(LinkedList_Spliterator) -> long - * Source: java/util/LinkedList.Spliterator.lsl:153 - */ - public long getExactSizeIfKnown() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _getFence() - this.index; - } - return result; - } - - /** - * [FUNCTION] LinkedList_SpliteratorAutomaton::tryAdvance(LinkedList_Spliterator, Consumer) -> boolean - * Source: java/util/LinkedList.Spliterator.lsl:166 - */ - public boolean tryAdvance(Consumer _action) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - final int hi = _getFence(); - final int i = this.index; - if (i < hi) { - Engine.assume(this.parent != null); - this.index = i + 1; - final SymbolicList parentStorage = ((LinkedList) ((Object) this.parent)).storage; - final Object item = parentStorage.get(i); - _action.accept(item); - if (((LinkedList) ((Object) this.parent)).modCount != this.expectedModCount) { - throw new ConcurrentModificationException(); - } - result = true; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] LinkedList_SpliteratorAutomaton::trySplit(LinkedList_Spliterator) -> Spliterator - * Source: java/util/LinkedList.Spliterator.lsl:196 - */ - public Spliterator trySplit() { - Spliterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int hi = _getFence(); - final int lo = this.index; - final int mid = (lo + hi) >>> 1; - if (lo >= mid) { - result = null; - } else { - result = (stub.java.util.LinkedList_Spliterator) ((Object) new LinkedList_Spliterator((Void) null, - /* state = */ LinkedList_Spliterator.__$lsl_States.Initialized, - /* parent = */ this.parent, - /* index = */ lo, - /* fence = */ mid, - /* expectedModCount = */ this.expectedModCount - )); - } - this.index = mid; - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(LinkedList_Spliterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/LinkedList_SubList$ListIterator.java b/approximations/src/main/java/generated/java/util/LinkedList_SubList$ListIterator.java deleted file mode 100644 index fb0bbd4f..00000000 --- a/approximations/src/main/java/generated/java/util/LinkedList_SubList$ListIterator.java +++ /dev/null @@ -1,277 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/LinkedList.lsl:82 -// - java/util/LinkedList.SubList.ListIterator.lsl:16 -// -package generated.java.util; - -import java.lang.IllegalStateException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ConcurrentModificationException; -import java.util.ListIterator; -import java.util.NoSuchElementException; -import java.util.function.Consumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import org.usvm.api.SymbolicList; -import runtime.LibSLRuntime; - -/** - * LinkedList_SubList_ListIteratorAutomaton for LinkedList_SubList_ListIterator ~> java.util.LinkedList_SubList$ListIterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.LinkedList_SubList$ListIterator.class) -public final class LinkedList_SubList$ListIterator implements LibSLRuntime.Automaton, ListIterator { - static { - Engine.assume(true); - } - - public LinkedList root; - - public LinkedList_SubList sublist; - - public int cursor; - - public int expectedModCount; - - public int offset; - - public int size; - - public int lastRet; - - @LibSLRuntime.AutomatonConstructor - public LinkedList_SubList$ListIterator(Void __$lsl_token, final byte p0, final LinkedList p1, - final LinkedList_SubList p2, final int p3, final int p4, final int p5, final int p6, - final int p7) { - this.root = p1; - this.sublist = p2; - this.cursor = p3; - this.expectedModCount = p4; - this.offset = p5; - this.size = p6; - this.lastRet = p7; - } - - @LibSLRuntime.AutomatonConstructor - public LinkedList_SubList$ListIterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, null, 0, 0, 0, 0, -1); - } - - /** - * [SUBROUTINE] LinkedList_SubList_ListIteratorAutomaton::_checkForComodification() -> void - * Source: java/util/LinkedList.SubList.ListIterator.lsl:58 - */ - private void _checkForComodification() { - /* body */ { - final int modCount = ((LinkedList) ((Object) this.root)).modCount; - if (modCount != this.expectedModCount) { - throw new ConcurrentModificationException(); - } - } - } - - /** - * [FUNCTION] LinkedList_SubList_ListIteratorAutomaton::hasPrevious(LinkedList_SubList_ListIterator) -> boolean - * Source: java/util/LinkedList.SubList.ListIterator.lsl:68 - */ - public boolean hasPrevious() { - boolean result = false; - /* body */ { - result = this.cursor != 0; - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubList_ListIteratorAutomaton::nextIndex(LinkedList_SubList_ListIterator) -> int - * Source: java/util/LinkedList.SubList.ListIterator.lsl:74 - */ - public int nextIndex() { - int result = 0; - /* body */ { - result = this.cursor; - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubList_ListIteratorAutomaton::previousIndex(LinkedList_SubList_ListIterator) -> int - * Source: java/util/LinkedList.SubList.ListIterator.lsl:80 - */ - public int previousIndex() { - int result = 0; - /* body */ { - result = this.cursor - 1; - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubList_ListIteratorAutomaton::hasNext(LinkedList_SubList_ListIterator) -> boolean - * Source: java/util/LinkedList.SubList.ListIterator.lsl:86 - */ - public boolean hasNext() { - boolean result = false; - /* body */ { - result = this.cursor != this.size; - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubList_ListIteratorAutomaton::next(LinkedList_SubList_ListIterator) -> Object - * Source: java/util/LinkedList.SubList.ListIterator.lsl:92 - */ - public Object next() { - Object result = null; - /* body */ { - Engine.assume(this.root != null); - _checkForComodification(); - final SymbolicList rootStorage = ((LinkedList) ((Object) this.root)).storage; - final int i = this.offset + this.cursor; - if (i >= rootStorage.size()) { - throw new NoSuchElementException(); - } - this.lastRet = this.cursor; - this.cursor += 1; - result = rootStorage.get(i); - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubList_ListIteratorAutomaton::previous(LinkedList_SubList_ListIterator) -> Object - * Source: java/util/LinkedList.SubList.ListIterator.lsl:112 - */ - public Object previous() { - Object result = null; - /* body */ { - Engine.assume(this.root != null); - _checkForComodification(); - final int i = (this.offset + this.cursor) - 1; - if (i < this.offset) { - throw new NoSuchElementException(); - } - final SymbolicList rootStorage = ((LinkedList) ((Object) this.root)).storage; - if (i >= rootStorage.size()) { - throw new ConcurrentModificationException(); - } - this.cursor -= 1; - this.lastRet = this.cursor; - result = rootStorage.get(i); - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubList_ListIteratorAutomaton::remove(LinkedList_SubList_ListIterator) -> void - * Source: java/util/LinkedList.SubList.ListIterator.lsl:135 - */ - public void remove() { - /* body */ { - Engine.assume(this.root != null); - if (this.lastRet < 0) { - throw new IllegalStateException(); - } - _checkForComodification(); - if (this.lastRet >= this.size) { - throw new ConcurrentModificationException(); - } else { - ((LinkedList) ((Object) this.root))._unlinkAny(this.offset + this.lastRet); - ((LinkedList_SubList) ((Object) this.sublist))._updateSizeAndModCount(-1); - this.expectedModCount = ((LinkedList) ((Object) this.root)).modCount; - this.size -= 1; - } - this.cursor = this.lastRet; - this.lastRet = -1; - } - } - - /** - * [FUNCTION] LinkedList_SubList_ListIteratorAutomaton::set(LinkedList_SubList_ListIterator, Object) -> void - * Source: java/util/LinkedList.SubList.ListIterator.lsl:163 - */ - public void set(Object e) { - /* body */ { - Engine.assume(this.root != null); - if (this.lastRet < 0) { - throw new IllegalStateException(); - } - _checkForComodification(); - final SymbolicList rootStorage = ((LinkedList) ((Object) this.root)).storage; - final int index = this.offset + this.lastRet; - if (index >= rootStorage.size()) { - throw new ConcurrentModificationException(); - } else { - rootStorage.set(index, e); - } - } - } - - /** - * [FUNCTION] LinkedList_SubList_ListIteratorAutomaton::add(LinkedList_SubList_ListIterator, Object) -> void - * Source: java/util/LinkedList.SubList.ListIterator.lsl:183 - */ - public void add(Object e) { - /* body */ { - Engine.assume(this.root != null); - _checkForComodification(); - final int i = this.offset + this.cursor; - if ((this.offset + this.lastRet) > ((LinkedList) ((Object) this.root)).storage.size()) { - throw new ConcurrentModificationException(); - } else { - ((LinkedList) ((Object) this.root))._linkAny(i, e); - ((LinkedList_SubList) ((Object) this.sublist))._updateSizeAndModCount(1); - this.expectedModCount = ((LinkedList) ((Object) this.root)).modCount; - this.size += 1; - } - this.cursor += 1; - this.lastRet = -1; - } - } - - /** - * [FUNCTION] LinkedList_SubList_ListIteratorAutomaton::forEachRemaining(LinkedList_SubList_ListIterator, Consumer) -> void - * Source: java/util/LinkedList.SubList.ListIterator.lsl:210 - */ - public void forEachRemaining(Consumer userAction) { - /* body */ { - Engine.assume(this.root != null); - if (userAction == null) { - throw new NullPointerException(); - } - int i = this.cursor; - if (i < this.size) { - i += this.offset; - final SymbolicList es = ((LinkedList) ((Object) this.root)).storage; - if (i >= es.size()) { - throw new ConcurrentModificationException(); - } - final int end = this.offset + this.size; - for (i = i; i < end; i += 1) { - final Object item = es.get(i); - userAction.accept(item); - } - ; - this.cursor = i - this.offset; - this.lastRet = this.cursor - 1; - _checkForComodification(); - } - } - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(LinkedList_SubList$ListIterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/LinkedList_SubList$Spliterator.java b/approximations/src/main/java/generated/java/util/LinkedList_SubList$Spliterator.java deleted file mode 100644 index e39f0cb6..00000000 --- a/approximations/src/main/java/generated/java/util/LinkedList_SubList$Spliterator.java +++ /dev/null @@ -1,212 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/LinkedList.lsl:72 -// - java/util/LinkedList.SubList.Spliterator.lsl:16 -// -package generated.java.util; - -import generated.runtime.LibSLGlobals; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ConcurrentModificationException; -import java.util.Spliterator; -import java.util.function.Consumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import org.usvm.api.SymbolicList; -import runtime.LibSLRuntime; - -/** - * LinkedList_SubList_SpliteratorAutomaton for LinkedList_SubList_Spliterator ~> java.util.LinkedList_SubList$Spliterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.LinkedList_SubList$Spliterator.class) -public final class LinkedList_SubList$Spliterator implements LibSLRuntime.Automaton, Spliterator { - static { - Engine.assume(true); - } - - public LinkedList root; - - public LinkedList_SubList parent; - - public int index; - - public int fence; - - public int expectedModCount; - - @LibSLRuntime.AutomatonConstructor - public LinkedList_SubList$Spliterator(Void __$lsl_token, final byte p0, final LinkedList p1, - final LinkedList_SubList p2, final int p3, final int p4, final int p5) { - this.root = p1; - this.parent = p2; - this.index = p3; - this.fence = p4; - this.expectedModCount = p5; - } - - @LibSLRuntime.AutomatonConstructor - public LinkedList_SubList$Spliterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, null, 0, -1, 0); - } - - /** - * [SUBROUTINE] LinkedList_SubList_SpliteratorAutomaton::_getFence() -> int - * Source: java/util/LinkedList.SubList.Spliterator.lsl:60 - */ - private int _getFence() { - int result = 0; - /* body */ { - if (this.fence == -1) { - Engine.assume(this.parent != null); - this.expectedModCount = ((LinkedList_SubList) ((Object) this.parent)).modCount; - this.fence = ((LinkedList_SubList) ((Object) this.parent)).length; - } - result = this.fence; - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubList_SpliteratorAutomaton::characteristics(LinkedList_SubList_Spliterator) -> int - * Source: java/util/LinkedList.SubList.Spliterator.lsl:80 - */ - public int characteristics() { - int result = 0; - /* body */ { - result = LibSLGlobals.SPLITERATOR_ORDERED | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED; - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubList_SpliteratorAutomaton::estimateSize(LinkedList_SubList_Spliterator) -> long - * Source: java/util/LinkedList.SubList.Spliterator.lsl:86 - */ - public long estimateSize() { - long result = 0L; - /* body */ { - result = _getFence() - this.index; - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubList_SpliteratorAutomaton::forEachRemaining(LinkedList_SubList_Spliterator, Consumer) -> void - * Source: java/util/LinkedList.SubList.Spliterator.lsl:92 - */ - public void forEachRemaining(Consumer _action) { - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - Engine.assume(this.root != null); - Engine.assume(this.parent != null); - final SymbolicList a = ((LinkedList) ((Object) this.root)).storage; - if (a == null) { - throw new ConcurrentModificationException(); - } - int hi = this.fence; - int mc = this.expectedModCount; - if (hi == -1) { - hi = ((LinkedList_SubList) ((Object) this.parent)).length; - mc = ((LinkedList_SubList) ((Object) this.parent)).modCount; - } - int i = this.index; - this.index = hi; - if ((i < 0) || (hi > ((LinkedList_SubList) ((Object) this.parent)).length)) { - throw new ConcurrentModificationException(); - } - for (i = i; i < hi; i += 1) { - final Object item = a.get(i); - _action.accept(item); - } - ; - if (mc != ((LinkedList_SubList) ((Object) this.parent)).modCount) { - throw new ConcurrentModificationException(); - } - } - } - - /** - * [FUNCTION] LinkedList_SubList_SpliteratorAutomaton::getExactSizeIfKnown(LinkedList_SubList_Spliterator) -> long - * Source: java/util/LinkedList.SubList.Spliterator.lsl:141 - */ - public long getExactSizeIfKnown() { - long result = 0L; - /* body */ { - result = _getFence() - this.index; - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubList_SpliteratorAutomaton::tryAdvance(LinkedList_SubList_Spliterator, Consumer) -> boolean - * Source: java/util/LinkedList.SubList.Spliterator.lsl:154 - */ - public boolean tryAdvance(Consumer _action) { - boolean result = false; - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - final int hi = _getFence(); - final int i = this.index; - if (i < hi) { - Engine.assume(this.root != null); - this.index = i + 1; - final SymbolicList rootStorage = ((LinkedList) ((Object) this.root)).storage; - final Object item = rootStorage.get(i); - _action.accept(item); - if (((LinkedList) ((Object) this.root)).modCount != this.expectedModCount) { - throw new ConcurrentModificationException(); - } - result = true; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubList_SpliteratorAutomaton::trySplit(LinkedList_SubList_Spliterator) -> Spliterator - * Source: java/util/LinkedList.SubList.Spliterator.lsl:184 - */ - public Spliterator trySplit() { - Spliterator result = null; - /* body */ { - final int hi = _getFence(); - final int lo = this.index; - final int mid = (lo + hi) >>> 1; - if (lo >= mid) { - result = null; - } else { - result = (stub.java.util.LinkedList_SubList$Spliterator) ((Object) new LinkedList_SubList$Spliterator((Void) null, - /* state = */ LinkedList_SubList$Spliterator.__$lsl_States.Initialized, - /* root = */ this.root, - /* parent = */ this.parent, - /* index = */ lo, - /* fence = */ mid, - /* expectedModCount = */ this.expectedModCount - )); - } - this.index = mid; - } - return result; - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(LinkedList_SubList$Spliterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/LinkedList_SubList.java b/approximations/src/main/java/generated/java/util/LinkedList_SubList.java deleted file mode 100644 index 62002017..00000000 --- a/approximations/src/main/java/generated/java/util/LinkedList_SubList.java +++ /dev/null @@ -1,908 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/LinkedList.lsl:61 -// - java/util/LinkedList.SubList.lsl:16 -// -package generated.java.util; - -import java.lang.Object; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Collection; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.RandomAccess; -import java.util.Spliterator; -import java.util.function.Consumer; -import java.util.function.IntFunction; -import java.util.function.Predicate; -import java.util.function.UnaryOperator; -import java.util.stream.Stream; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import org.usvm.api.SymbolicList; -import runtime.LibSLRuntime; -import stub.java.util.stream.StreamLSL; - -/** - * LinkedList_SubListAutomaton for LinkedList_SubList ~> java.util.LinkedList_SubList - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.LinkedList_SubList.class) -public final class LinkedList_SubList implements LibSLRuntime.Automaton, List, RandomAccess { - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public LinkedList root; - - public LinkedList_SubList parentList; - - public int offset; - - public int length; - - public int modCount; - - @LibSLRuntime.AutomatonConstructor - public LinkedList_SubList(Void __$lsl_token, final byte p0, final LinkedList p1, - final LinkedList_SubList p2, final int p3, final int p4, final int p5) { - this.__$lsl_state = p0; - this.root = p1; - this.parentList = p2; - this.offset = p3; - this.length = p4; - this.modCount = p5; - } - - @LibSLRuntime.AutomatonConstructor - public LinkedList_SubList(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, null, null, 0, 0, 0); - } - - /** - * [CONSTRUCTOR] LinkedList_SubListAutomaton::(LinkedList_SubList, LinkedList, int, int) -> void - * Source: java/util/LinkedList.SubList.lsl:211 - */ - public LinkedList_SubList(LinkedList root, int fromIndex, int toIndex) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - LibSLRuntime.not_implemented(/* inaccessible constructor */); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] LinkedList_SubListAutomaton::(LinkedList_SubList, LinkedList_SubList, int, int) -> void - * Source: java/util/LinkedList.SubList.lsl:218 - */ - private LinkedList_SubList(LinkedList_SubList parent, int fromIndex, int toIndex) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - LibSLRuntime.not_implemented(/* inaccessible constructor */); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] LinkedList_SubListAutomaton::_addAllElements(int, Collection) -> boolean - * Source: java/util/LinkedList.SubList.lsl:91 - */ - private boolean _addAllElements(int index, Collection c) { - boolean result = false; - /* body */ { - Engine.assume(this.root != null); - final int effectiveIndex = this.offset + index; - ((LinkedList) ((Object) this.root))._checkPositionIndex(effectiveIndex); - final int collectionSize = c.size(); - if (collectionSize == 0) { - result = false; - } else { - result = true; - ((LinkedList) ((Object) this.root))._checkForComodification(this.modCount); - ((LinkedList) ((Object) this.root))._addAllElements(effectiveIndex, c); - _updateSizeAndModCount(collectionSize); - } - } - return result; - } - - /** - * [SUBROUTINE] LinkedList_SubListAutomaton::_updateSizeAndModCount(int) -> void - * Source: java/util/LinkedList.SubList.lsl:114 - */ - public void _updateSizeAndModCount(int sizeChange) { - /* body */ { - Engine.assume(this.root != null); - this.length += sizeChange; - this.modCount = ((LinkedList) ((Object) this.root)).modCount; - LinkedList_SubList aList = this.parentList; - while (aList != null) { - ((LinkedList_SubList) ((Object) aList)).length += sizeChange; - ((LinkedList_SubList) ((Object) aList)).modCount = this.modCount; - aList = ((LinkedList_SubList) ((Object) aList)).parentList; - } - ; - } - } - - /** - * [SUBROUTINE] LinkedList_SubListAutomaton::_indexOfElement(Object) -> int - * Source: java/util/LinkedList.SubList.lsl:139 - */ - private int _indexOfElement(Object o) { - int result = 0; - /* body */ { - Engine.assume(this.root != null); - ((LinkedList) ((Object) this.root))._checkForComodification(this.modCount); - final SymbolicList parentStorage = ((LinkedList) ((Object) this.root)).storage; - final int index = LibSLRuntime.ListActions.find(parentStorage, o, this.offset, this.offset + this.length); - if (index != -1) { - result = index - this.offset; - } else { - result = -1; - } - } - return result; - } - - /** - * [SUBROUTINE] LinkedList_SubListAutomaton::_makeStream(boolean) -> Stream - * Source: java/util/LinkedList.SubList.lsl:154 - */ - private Stream _makeStream(boolean parallel) { - Stream result = null; - /* body */ { - Engine.assume(this.root != null); - ((LinkedList) ((Object) this.root))._checkForComodification(this.modCount); - final SymbolicList parentStorage = ((LinkedList) ((Object) this.root)).storage; - final int count = this.length; - final Object[] items = new Object[count]; - int i = 0; - for (i = 0; i < count; i += 1) { - items[i] = parentStorage.get(this.offset + i); - } - ; - result = (StreamLSL) ((Object) new generated.java.util.stream.StreamLSL((Void) null, - /* state = */ generated.java.util.stream.StreamLSL.__$lsl_States.Initialized, - /* storage = */ items, - /* length = */ count, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ parallel, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [SUBROUTINE] LinkedList_SubListAutomaton::_batchRemove(Collection, boolean) -> boolean - * Source: java/util/LinkedList.SubList.lsl:186 - */ - private boolean _batchRemove(Collection c, boolean complement) { - boolean result = false; - /* body */ { - Engine.assume(this.root != null); - ((LinkedList) ((Object) this.root))._checkForComodification(this.modCount); - if (this.length != 0) { - final int oldRootLength = ((LinkedList) ((Object) this.root)).storage.size(); - result = ((LinkedList) ((Object) this.root))._batchRemove(c, complement, this.offset, this.offset + this.length); - if (result) { - final int newRootLength = ((LinkedList) ((Object) this.root)).storage.size(); - _updateSizeAndModCount(newRootLength - oldRootLength); - } - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::add(LinkedList_SubList, Object) -> boolean - * Source: java/util/LinkedList.SubList.lsl:230 - */ - public boolean add(Object e) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((LinkedList) ((Object) this.root))._checkForComodification(this.modCount); - final int effectiveIndex = this.offset + this.length; - ((LinkedList) ((Object) this.root))._linkAny(effectiveIndex, e); - _updateSizeAndModCount(1); - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::add(LinkedList_SubList, int, Object) -> void - * Source: java/util/LinkedList.SubList.lsl:243 - */ - public void add(int index, Object element) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((LinkedList) ((Object) this.root))._checkForComodification(this.modCount); - final int effectiveIndex = this.offset + index; - ((LinkedList) ((Object) this.root))._linkAny(effectiveIndex, element); - _updateSizeAndModCount(1); - } - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::addAll(LinkedList_SubList, Collection) -> boolean - * Source: java/util/LinkedList.SubList.lsl:256 - */ - public boolean addAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _addAllElements(this.length, c); - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::addAll(LinkedList_SubList, int, Collection) -> boolean - * Source: java/util/LinkedList.SubList.lsl:262 - */ - public boolean addAll(int index, Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _addAllElements(index, c); - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::clear(LinkedList_SubList) -> void - * Source: java/util/LinkedList.SubList.lsl:269 - */ - public void clear() { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((LinkedList) ((Object) this.root))._checkForComodification(this.modCount); - final int size = this.length; - if (size != 0) { - Engine.assume(size > 0); - final int end = this.offset - 1; - final int start = end + size; - final SymbolicList rootStorage = ((LinkedList) ((Object) this.root)).storage; - int i = 0; - for (i = start; i > end; i += -1) { - rootStorage.remove(i); - } - ; - ((LinkedList) ((Object) this.root)).modCount += 1; - _updateSizeAndModCount(-size); - } - } - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::contains(LinkedList_SubList, Object) -> boolean - * Source: java/util/LinkedList.SubList.lsl:301 - */ - public boolean contains(Object o) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _indexOfElement(o) != -1; - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::containsAll(LinkedList_SubList, Collection) -> boolean - * Source: java/util/LinkedList.SubList.lsl:308 - */ - public boolean containsAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = true; - if (!c.isEmpty()) { - Engine.assume(this.root != null); - final SymbolicList rootStorage = ((LinkedList) ((Object) this.root)).storage; - final int end = this.offset + this.length; - if ((c != null && c.getClass() == stub.java.util.LinkedList_SubList.class)) { - final LinkedList otherRoot = ((LinkedList_SubList) ((Object) c)).root; - Engine.assume(otherRoot != null); - final SymbolicList otherStorage = ((LinkedList) ((Object) otherRoot)).storage; - final int otherOffset = ((LinkedList_SubList) ((Object) c)).offset; - final int otherEnd = otherOffset + ((LinkedList_SubList) ((Object) c)).length; - Engine.assume(otherStorage != null); - Engine.assume(otherOffset >= 0); - Engine.assume(otherEnd >= 0); - int i = otherOffset; - while (result && (i < otherEnd)) { - final Object item = otherStorage.get(i); - result = LibSLRuntime.ListActions.find(rootStorage, item, this.offset, end) != -1; - i += 1; - } - ; - } else { - final Iterator iter = c.iterator(); - while (result && iter.hasNext()) { - final Object item = iter.next(); - result = LibSLRuntime.ListActions.find(rootStorage, item, this.offset, end) != -1; - } - ; - } - } - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::equals(LinkedList_SubList, Object) -> boolean - * Source: java/util/LinkedList.SubList.lsl:364 - */ - public boolean equals(Object o) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (o == this) { - result = true; - } else { - result = (o != null && o.getClass() == stub.java.util.LinkedList_SubList.class); - if (result) { - Engine.assume(this.root != null); - final int otherLength = ((LinkedList_SubList) ((Object) o)).length; - Engine.assume(otherLength >= 0); - result = this.length == otherLength; - if (result) { - result = ((LinkedList) ((Object) this.root))._equalsRange(((List) o), this.offset, this.offset + this.length); - ((LinkedList) ((Object) this.root))._checkForComodification(this.modCount); - } - } - } - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::forEach(LinkedList_SubList, Consumer) -> void - * Source: java/util/LinkedList.SubList.lsl:392 - */ - public void forEach(Consumer _action) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.length != 0) { - Engine.assume(this.length > 0); - Engine.assume(this.root != null); - final SymbolicList rootStorage = ((LinkedList) ((Object) this.root)).storage; - final int expectedModCount = ((LinkedList) ((Object) this.root)).modCount; - this.modCount = expectedModCount; - int i = this.offset; - final int end = this.offset + this.length; - while ((i < end) && (((LinkedList) ((Object) this.root)).modCount == expectedModCount)) { - final Object item = rootStorage.get(i); - _action.accept(item); - i += 1; - } - ; - ((LinkedList) ((Object) this.root))._checkForComodification(expectedModCount); - } - } - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::get(LinkedList_SubList, int) -> Object - * Source: java/util/LinkedList.SubList.lsl:424 - */ - public Object get(int index) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((LinkedList) ((Object) this.root))._checkElementIndex(index, this.length); - ((LinkedList) ((Object) this.root))._checkForComodification(this.modCount); - final int effectiveIndex = this.offset + index; - result = ((LinkedList) ((Object) this.root)).storage.get(effectiveIndex); - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::hashCode(LinkedList_SubList) -> int - * Source: java/util/LinkedList.SubList.lsl:436 - */ - public int hashCode() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = 1; - if (this.length != 0) { - Engine.assume(this.length > 0); - Engine.assume(this.root != null); - final SymbolicList rootStorage = ((LinkedList) ((Object) this.root)).storage; - int i = this.offset; - final int end = this.offset + this.length; - for (i = i; i < end; i += 1) { - final Object item = rootStorage.get(i); - result = (31 * result) + LibSLRuntime.hashCode(item); - } - ; - ((LinkedList) ((Object) this.root))._checkForComodification(this.modCount); - } - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::indexOf(LinkedList_SubList, Object) -> int - * Source: java/util/LinkedList.SubList.lsl:464 - */ - public int indexOf(Object o) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _indexOfElement(o); - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::isEmpty(LinkedList_SubList) -> boolean - * Source: java/util/LinkedList.SubList.lsl:471 - */ - public boolean isEmpty() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.length == 0; - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::iterator(LinkedList_SubList) -> Iterator - * Source: java/util/LinkedList.SubList.lsl:477 - */ - public Iterator iterator() { - Iterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (stub.java.util.LinkedList_SubList$ListIterator) ((Object) new LinkedList_SubList$ListIterator((Void) null, - /* state = */ LinkedList_SubList$ListIterator.__$lsl_States.Initialized, - /* root = */ this.root, - /* sublist = */ this, - /* cursor = */ 0, - /* expectedModCount = */ this.modCount, - /* offset = */ this.offset, - /* size = */ this.length, - /* lastRet = */ -1 - )); - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::lastIndexOf(LinkedList_SubList, Object) -> int - * Source: java/util/LinkedList.SubList.lsl:490 - */ - public int lastIndexOf(Object o) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((LinkedList) ((Object) this.root))._checkForComodification(this.modCount); - if (this.length == 0) { - result = -1; - } else { - Engine.assume(this.length > 0); - final int end = this.offset + this.length; - final SymbolicList rootStorage = ((LinkedList) ((Object) this.root)).storage; - result = LibSLRuntime.ListActions.find(rootStorage, o, this.offset, end); - if (result != -1) { - final int nextIndex = result + 1; - if (nextIndex < end) { - final int rightIndex = LibSLRuntime.ListActions.find(rootStorage, o, nextIndex, end); - Engine.assume(rightIndex == -1); - } - result -= this.offset; - } - } - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::listIterator(LinkedList_SubList) -> ListIterator - * Source: java/util/LinkedList.SubList.lsl:524 - */ - public ListIterator listIterator() { - ListIterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (stub.java.util.LinkedList_SubList$ListIterator) ((Object) new LinkedList_SubList$ListIterator((Void) null, - /* state = */ LinkedList_SubList$ListIterator.__$lsl_States.Initialized, - /* root = */ this.root, - /* sublist = */ this, - /* cursor = */ 0, - /* expectedModCount = */ this.modCount, - /* offset = */ this.offset, - /* size = */ this.length, - /* lastRet = */ -1 - )); - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::listIterator(LinkedList_SubList, int) -> ListIterator - * Source: java/util/LinkedList.SubList.lsl:537 - */ - public ListIterator listIterator(int index) { - ListIterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (stub.java.util.LinkedList_SubList$ListIterator) ((Object) new LinkedList_SubList$ListIterator((Void) null, - /* state = */ LinkedList_SubList$ListIterator.__$lsl_States.Initialized, - /* root = */ this.root, - /* sublist = */ this, - /* cursor = */ index, - /* expectedModCount = */ this.modCount, - /* offset = */ this.offset, - /* size = */ this.length, - /* lastRet = */ -1 - )); - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::parallelStream(LinkedList_SubList) -> Stream - * Source: java/util/LinkedList.SubList.lsl:551 - */ - public Stream parallelStream() { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _makeStream(true); - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::remove(LinkedList_SubList, Object) -> boolean - * Source: java/util/LinkedList.SubList.lsl:558 - */ - public boolean remove(Object o) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - final int end = this.offset + this.length; - final SymbolicList rootStorage = ((LinkedList) ((Object) this.root)).storage; - final int index = LibSLRuntime.ListActions.find(rootStorage, o, this.offset, end); - result = index != -1; - if (result) { - ((LinkedList) ((Object) this.root))._checkForComodification(this.modCount); - ((LinkedList) ((Object) this.root))._unlinkAny(index); - _updateSizeAndModCount(-1); - } - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::remove(LinkedList_SubList, int) -> Object - * Source: java/util/LinkedList.SubList.lsl:578 - */ - public Object remove(int index) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((LinkedList) ((Object) this.root))._checkElementIndex(index, this.length); - ((LinkedList) ((Object) this.root))._checkForComodification(this.modCount); - final int effectiveIndex = this.offset + index; - result = ((LinkedList) ((Object) this.root))._unlinkAny(effectiveIndex); - _updateSizeAndModCount(-1); - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::removeAll(LinkedList_SubList, Collection) -> boolean - * Source: java/util/LinkedList.SubList.lsl:592 - */ - public boolean removeAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _batchRemove(c, false); - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::removeIf(LinkedList_SubList, Predicate) -> boolean - * Source: java/util/LinkedList.SubList.lsl:598 - */ - public boolean removeIf(Predicate filter) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((LinkedList) ((Object) this.root))._checkForComodification(this.modCount); - final int size = this.length; - if (size != 0) { - final int oldRootLength = ((LinkedList) ((Object) this.root)).storage.size(); - result = ((LinkedList) ((Object) this.root))._removeIf(filter, this.offset, this.offset + this.length); - if (result) { - final int newRootLength = ((LinkedList) ((Object) this.root)).storage.size(); - _updateSizeAndModCount(newRootLength - oldRootLength); - } - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::replaceAll(LinkedList_SubList, UnaryOperator) -> void - * Source: java/util/LinkedList.SubList.lsl:622 - */ - public void replaceAll(UnaryOperator operator) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((LinkedList) ((Object) this.root))._replaceAllRange(operator, this.offset, this.offset + this.length); - } - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::retainAll(LinkedList_SubList, Collection) -> boolean - * Source: java/util/LinkedList.SubList.lsl:629 - */ - public boolean retainAll(Collection c) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _batchRemove(c, true); - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::set(LinkedList_SubList, int, Object) -> Object - * Source: java/util/LinkedList.SubList.lsl:635 - */ - public Object set(int index, Object element) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((LinkedList) ((Object) this.root))._checkElementIndex(index, this.length); - ((LinkedList) ((Object) this.root))._checkForComodification(this.modCount); - final SymbolicList parentStorage = ((LinkedList) ((Object) this.root)).storage; - final int effectiveIndex = this.offset + index; - result = parentStorage.get(effectiveIndex); - parentStorage.set(effectiveIndex, element); - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::size(LinkedList_SubList) -> int - * Source: java/util/LinkedList.SubList.lsl:649 - */ - public int size() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((LinkedList) ((Object) this.root))._checkForComodification(this.modCount); - result = this.length; - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::sort(LinkedList_SubList, Comparator) -> void - * Source: java/util/LinkedList.SubList.lsl:659 - */ - public void sort(Comparator c) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((LinkedList) ((Object) this.root))._do_sort(this.offset, this.offset + this.length, c); - this.modCount = ((LinkedList) ((Object) this.root)).modCount; - } - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::spliterator(LinkedList_SubList) -> Spliterator - * Source: java/util/LinkedList.SubList.lsl:667 - */ - public Spliterator spliterator() { - Spliterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (stub.java.util.LinkedList_SubList$Spliterator) ((Object) new LinkedList_SubList$Spliterator((Void) null, - /* state = */ LinkedList_SubList$Spliterator.__$lsl_States.Initialized, - /* root = */ this.root, - /* parent = */ this, - /* index = */ 0, - /* fence = */ -1, - /* expectedModCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::stream(LinkedList_SubList) -> Stream - * Source: java/util/LinkedList.SubList.lsl:677 - */ - public Stream stream() { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _makeStream(false); - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::subList(LinkedList_SubList, int, int) -> List - * Source: java/util/LinkedList.SubList.lsl:683 - */ - public List subList(int fromIndex, int toIndex) { - List result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((LinkedList) ((Object) this.root))._subListRangeCheck(fromIndex, toIndex, this.length); - result = (stub.java.util.LinkedList_SubList) ((Object) new LinkedList_SubList((Void) null, - /* state = */ LinkedList_SubList.__$lsl_States.Initialized, - /* root = */ this.root, - /* parentList = */ this, - /* offset = */ this.offset + fromIndex, - /* length = */ toIndex - fromIndex, - /* modCount = */ this.modCount - )); - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::toArray(LinkedList_SubList) -> array - * Source: java/util/LinkedList.SubList.lsl:699 - */ - public Object[] toArray() { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((LinkedList) ((Object) this.root))._checkForComodification(this.modCount); - result = new Object[this.length]; - final SymbolicList rootStorage = ((LinkedList) ((Object) this.root)).storage; - final int end = this.offset + this.length; - int i = 0; - int j = 0; - for (i = this.offset; i < end; i += 1) { - result[j] = rootStorage.get(i); - j += 1; - } - ; - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::toArray(LinkedList_SubList, IntFunction) -> array - * Source: java/util/LinkedList.SubList.lsl:724 - */ - public Object[] toArray(IntFunction generator) { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final Object[] a = ((Object[]) generator.apply(0)); - final int aSize = a.length; - Engine.assume(this.root != null); - ((LinkedList) ((Object) this.root))._checkForComodification(this.modCount); - result = new Object[this.length]; - final SymbolicList rootStorage = ((LinkedList) ((Object) this.root)).storage; - final int end = this.offset + this.length; - int i = 0; - int j = 0; - for (i = this.offset; i < end; i += 1) { - result[j] = rootStorage.get(i); - j += 1; - } - ; - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::toArray(LinkedList_SubList, array) -> array - * Source: java/util/LinkedList.SubList.lsl:746 - */ - public Object[] toArray(Object[] a) { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(this.root != null); - ((LinkedList) ((Object) this.root))._checkForComodification(this.modCount); - final int aSize = a.length; - if (aSize < this.length) { - a = new Object[this.length]; - } - result = a; - final SymbolicList rootStorage = ((LinkedList) ((Object) this.root)).storage; - final int end = this.offset + this.length; - int i = 0; - int j = 0; - for (i = this.offset; i < end; i += 1) { - result[j] = rootStorage.get(i); - j += 1; - } - ; - if (aSize > this.length) { - result[aSize] = null; - } - } - return result; - } - - /** - * [FUNCTION] LinkedList_SubListAutomaton::toString(LinkedList_SubList) -> String - * Source: java/util/LinkedList.SubList.lsl:773 - */ - public String toString() { - String result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.length == 0) { - result = "[]"; - } else { - result = "["; - Engine.assume(this.root != null); - final SymbolicList rootStorage = ((LinkedList) ((Object) this.root)).storage; - int i = this.offset; - final int end = this.offset + this.length; - int counter = this.length; - for (i = i; i < end; i += 1) { - final Object item = rootStorage.get(i); - result = result.concat(LibSLRuntime.toString(item)); - counter -= 1; - if (counter != 0) { - result = result.concat(", "); - } - } - ; - result = result.concat("]"); - } - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(LinkedList_SubList.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/List.java b/approximations/src/main/java/generated/java/util/List.java deleted file mode 100644 index 86752101..00000000 --- a/approximations/src/main/java/generated/java/util/List.java +++ /dev/null @@ -1,333 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/List.lsl:25 -// - java/util/List.main.lsl:21 -// -package generated.java.util; - -import java.lang.Class; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Collection; -import java.util.Iterator; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import org.usvm.api.SymbolicList; -import runtime.LibSLRuntime; - -/** - * ListAutomaton for LSLList ~> java.util.List - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.util.List.class) -public interface List extends LibSLRuntime.Automaton, java.util.List { - Class __$_lsl_INIT_INTERFACE_ListAutomaton_5013495c = Void.class; - - /** - * [FUNCTION] ListAutomaton::copyOf(Collection) -> List - * Source: java/util/List.main.lsl:62 - */ - static java.util.List copyOf(Collection coll) { - java.util.List result = null; - /* body */ { - final SymbolicList data = Engine.makeSymbolicList(); - int size = 0; - final Iterator iter = coll.iterator(); - while (iter.hasNext()) { - final Object item = iter.next(); - data.insert(size, item); - size += 1; - } - ; - result = (java.util.ArrayList) ((Object) new ArrayList((Void) null, - /* state = */ ArrayList.__$lsl_States.Initialized, - /* storage = */ data, - /* modCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] ListAutomaton::of() -> List - * Source: java/util/List.main.lsl:86 - */ - static java.util.List of() { - java.util.List result = null; - /* body */ { - result = (java.util.ArrayList) ((Object) new ArrayList((Void) null, - /* state = */ ArrayList.__$lsl_States.Initialized, - /* storage = */ Engine.makeSymbolicList(), - /* modCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] ListAutomaton::of(Object) -> List - * Source: java/util/List.main.lsl:94 - */ - static java.util.List of(Object e1) { - java.util.List result = null; - /* body */ { - final SymbolicList data = Engine.makeSymbolicList(); - data.insert(0, e1); - result = (java.util.ArrayList) ((Object) new ArrayList((Void) null, - /* state = */ ArrayList.__$lsl_States.Initialized, - /* storage = */ data, - /* modCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] ListAutomaton::of(Object, Object) -> List - * Source: java/util/List.main.lsl:106 - */ - static java.util.List of(Object e1, Object e2) { - java.util.List result = null; - /* body */ { - final SymbolicList data = Engine.makeSymbolicList(); - data.insert(0, e1); - data.insert(1, e2); - result = (java.util.ArrayList) ((Object) new ArrayList((Void) null, - /* state = */ ArrayList.__$lsl_States.Initialized, - /* storage = */ data, - /* modCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] ListAutomaton::of(Object, Object, Object) -> List - * Source: java/util/List.main.lsl:119 - */ - static java.util.List of(Object e1, Object e2, Object e3) { - java.util.List result = null; - /* body */ { - final SymbolicList data = Engine.makeSymbolicList(); - data.insert(0, e1); - data.insert(1, e2); - data.insert(2, e3); - result = (java.util.ArrayList) ((Object) new ArrayList((Void) null, - /* state = */ ArrayList.__$lsl_States.Initialized, - /* storage = */ data, - /* modCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] ListAutomaton::of(Object, Object, Object, Object) -> List - * Source: java/util/List.main.lsl:133 - */ - static java.util.List of(Object e1, Object e2, Object e3, Object e4) { - java.util.List result = null; - /* body */ { - final SymbolicList data = Engine.makeSymbolicList(); - data.insert(0, e1); - data.insert(1, e2); - data.insert(2, e3); - data.insert(3, e4); - result = (java.util.ArrayList) ((Object) new ArrayList((Void) null, - /* state = */ ArrayList.__$lsl_States.Initialized, - /* storage = */ data, - /* modCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] ListAutomaton::of(Object, Object, Object, Object, Object) -> List - * Source: java/util/List.main.lsl:148 - */ - static java.util.List of(Object e1, Object e2, Object e3, Object e4, Object e5) { - java.util.List result = null; - /* body */ { - final SymbolicList data = Engine.makeSymbolicList(); - data.insert(0, e1); - data.insert(1, e2); - data.insert(2, e3); - data.insert(3, e4); - data.insert(4, e5); - result = (java.util.ArrayList) ((Object) new ArrayList((Void) null, - /* state = */ ArrayList.__$lsl_States.Initialized, - /* storage = */ data, - /* modCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] ListAutomaton::of(Object, Object, Object, Object, Object, Object) -> List - * Source: java/util/List.main.lsl:164 - */ - static java.util.List of(Object e1, Object e2, Object e3, Object e4, Object e5, Object e6) { - java.util.List result = null; - /* body */ { - final SymbolicList data = Engine.makeSymbolicList(); - data.insert(0, e1); - data.insert(1, e2); - data.insert(2, e3); - data.insert(3, e4); - data.insert(4, e5); - data.insert(5, e6); - result = (java.util.ArrayList) ((Object) new ArrayList((Void) null, - /* state = */ ArrayList.__$lsl_States.Initialized, - /* storage = */ data, - /* modCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] ListAutomaton::of(Object, Object, Object, Object, Object, Object, Object) -> List - * Source: java/util/List.main.lsl:181 - */ - static java.util.List of(Object e1, Object e2, Object e3, Object e4, Object e5, Object e6, - Object e7) { - java.util.List result = null; - /* body */ { - final SymbolicList data = Engine.makeSymbolicList(); - data.insert(0, e1); - data.insert(1, e2); - data.insert(2, e3); - data.insert(3, e4); - data.insert(4, e5); - data.insert(5, e6); - data.insert(6, e7); - result = (java.util.ArrayList) ((Object) new ArrayList((Void) null, - /* state = */ ArrayList.__$lsl_States.Initialized, - /* storage = */ data, - /* modCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] ListAutomaton::of(Object, Object, Object, Object, Object, Object, Object, Object) -> List - * Source: java/util/List.main.lsl:199 - */ - static java.util.List of(Object e1, Object e2, Object e3, Object e4, Object e5, Object e6, - Object e7, Object e8) { - java.util.List result = null; - /* body */ { - final SymbolicList data = Engine.makeSymbolicList(); - data.insert(0, e1); - data.insert(1, e2); - data.insert(2, e3); - data.insert(3, e4); - data.insert(4, e5); - data.insert(5, e6); - data.insert(6, e7); - data.insert(7, e8); - result = (java.util.ArrayList) ((Object) new ArrayList((Void) null, - /* state = */ ArrayList.__$lsl_States.Initialized, - /* storage = */ data, - /* modCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] ListAutomaton::of(Object, Object, Object, Object, Object, Object, Object, Object, Object) -> List - * Source: java/util/List.main.lsl:218 - */ - static java.util.List of(Object e1, Object e2, Object e3, Object e4, Object e5, Object e6, - Object e7, Object e8, Object e9) { - java.util.List result = null; - /* body */ { - final SymbolicList data = Engine.makeSymbolicList(); - data.insert(0, e1); - data.insert(1, e2); - data.insert(2, e3); - data.insert(3, e4); - data.insert(4, e5); - data.insert(5, e6); - data.insert(6, e7); - data.insert(7, e8); - data.insert(8, e9); - result = (java.util.ArrayList) ((Object) new ArrayList((Void) null, - /* state = */ ArrayList.__$lsl_States.Initialized, - /* storage = */ data, - /* modCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] ListAutomaton::of(Object, Object, Object, Object, Object, Object, Object, Object, Object, Object) -> List - * Source: java/util/List.main.lsl:238 - */ - static java.util.List of(Object e1, Object e2, Object e3, Object e4, Object e5, Object e6, - Object e7, Object e8, Object e9, Object e10) { - java.util.List result = null; - /* body */ { - final SymbolicList data = Engine.makeSymbolicList(); - data.insert(0, e1); - data.insert(1, e2); - data.insert(2, e3); - data.insert(3, e4); - data.insert(4, e5); - data.insert(5, e6); - data.insert(6, e7); - data.insert(7, e8); - data.insert(8, e9); - data.insert(9, e10); - result = (java.util.ArrayList) ((Object) new ArrayList((Void) null, - /* state = */ ArrayList.__$lsl_States.Initialized, - /* storage = */ data, - /* modCount = */ 0 - )); - } - return result; - } - - /** - * [FUNCTION] ListAutomaton::of(array) -> List - * Source: java/util/List.main.lsl:259 - */ - static java.util.List of(Object[] elements) { - java.util.List result = null; - /* body */ { - final SymbolicList data = Engine.makeSymbolicList(); - final int size = elements.length; - Engine.assume(size >= 0); - if (size != 0) { - int i = 0; - for (i = 0; i < size; i += 1) { - data.insert(i, elements[i]); - } - ; - } - result = (java.util.ArrayList) ((Object) new ArrayList((Void) null, - /* state = */ ArrayList.__$lsl_States.Initialized, - /* storage = */ data, - /* modCount = */ 0 - )); - } - return result; - } - - final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(List.class) - final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/MappedByteBufferImpl.java b/approximations/src/main/java/generated/java/util/MappedByteBufferImpl.java new file mode 100644 index 00000000..d358e0cb --- /dev/null +++ b/approximations/src/main/java/generated/java/util/MappedByteBufferImpl.java @@ -0,0 +1,95 @@ +package generated.java.util; + +import jdk.internal.access.foreign.UnmapperProxy; +import org.jacodb.approximation.annotation.Approximate; + +import java.io.FileDescriptor; +import java.nio.MappedByteBuffer; + +@Approximate(java.nio.MappedByteBuffer.class) +public abstract class MappedByteBufferImpl extends ByteBufferImpl { + private final boolean isSync; + + MappedByteBufferImpl(int mark, int pos, int lim, int cap, + FileDescriptor fd, boolean isSync, byte[] segment) { + super(mark, pos, lim, cap, segment); + throw new UnsupportedOperationException(); + } + + MappedByteBufferImpl(int mark, int pos, int lim, int cap, + boolean isSync, byte[] segment) { + super(mark, pos, lim, cap, segment); + this.isSync = isSync; + } + + MappedByteBufferImpl(int mark, int pos, int lim, int cap, byte[] segment) { + super(mark, pos, lim, cap, segment); + this.isSync = false; + } + + UnmapperProxy unmapper() { + throw new UnsupportedOperationException(); + } + + private boolean isSync() { + return isSync; + } + + public final boolean isLoaded() { + throw new UnsupportedOperationException(); + } + + public final MappedByteBuffer load() { + throw new UnsupportedOperationException(); + } + + public final MappedByteBuffer force() { + throw new UnsupportedOperationException(); + } + + public final MappedByteBuffer force(int index, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public final MappedByteBufferImpl position(int newPosition) { + super.position(newPosition); + return this; + } + + @Override + public final MappedByteBufferImpl limit(int newLimit) { + super.limit(newLimit); + return this; + } + + @Override + public final MappedByteBufferImpl mark() { + super.mark(); + return this; + } + + @Override + public final MappedByteBufferImpl reset() { + super.reset(); + return this; + } + + @Override + public final MappedByteBufferImpl clear() { + super.clear(); + return this; + } + + @Override + public final MappedByteBufferImpl flip() { + super.flip(); + return this; + } + + @Override + public final MappedByteBufferImpl rewind() { + super.rewind(); + return this; + } +} diff --git a/approximations/src/main/java/generated/java/util/Optional.java b/approximations/src/main/java/generated/java/util/Optional.java deleted file mode 100644 index 09a3419a..00000000 --- a/approximations/src/main/java/generated/java/util/Optional.java +++ /dev/null @@ -1,480 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/Optional.lsl:40 -// - java/util/Optional.automata.lsl:22 -// -package generated.java.util; - -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.Runnable; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.NoSuchElementException; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.function.Supplier; -import java.util.stream.Stream; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; -import stub.java.util.stream.StreamLSL; - -/** - * OptionalAutomaton for LSLOptional ~> java.util.Optional - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.util.Optional.class) -public final class Optional implements LibSLRuntime.Automaton { - private static java.util.Optional EMPTY = null; - - static { - /* OptionalAutomaton::() */ { - EMPTY = (java.util.Optional) ((Object) new Optional((Void) null, - /* state = */ Optional.__$lsl_States.Initialized, - /* value = */ null - )); - } - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public Object value; - - @LibSLRuntime.AutomatonConstructor - public Optional(Void __$lsl_token, final byte p0, final Object p1) { - this.__$lsl_state = p0; - this.value = p1; - } - - @LibSLRuntime.AutomatonConstructor - public Optional(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, null); - } - - /** - * [CONSTRUCTOR] OptionalAutomaton::(LSLOptional) -> void - * Source: java/util/Optional.automata.lsl:77 - */ - private Optional() { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - LibSLRuntime.error("Private constructor call"); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] OptionalAutomaton::(LSLOptional, Object) -> void - * Source: java/util/Optional.automata.lsl:87 - */ - private Optional(Object obj) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - LibSLRuntime.error("Private constructor call"); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [FUNCTION] OptionalAutomaton::empty() -> Optional - * Source: java/util/Optional.automata.lsl:103 - */ - public static java.util.Optional empty() { - java.util.Optional result = null; - // WARNING: no state checks in static context - /* body */ { - result = EMPTY; - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] OptionalAutomaton::of(Object) -> Optional - * Source: java/util/Optional.automata.lsl:111 - */ - public static java.util.Optional of(Object obj) { - java.util.Optional result = null; - // WARNING: no state checks in static context - /* body */ { - if (obj == null) { - throw new NullPointerException(); - } - result = (java.util.Optional) ((Object) new Optional((Void) null, - /* state = */ Optional.__$lsl_States.Initialized, - /* value = */ obj - )); - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] OptionalAutomaton::ofNullable(Object) -> Optional - * Source: java/util/Optional.automata.lsl:126 - */ - public static java.util.Optional ofNullable(Object obj) { - java.util.Optional result = null; - // WARNING: no state checks in static context - /* body */ { - if (obj == null) { - result = EMPTY; - } else { - result = (java.util.Optional) ((Object) new Optional((Void) null, - /* state = */ Optional.__$lsl_States.Initialized, - /* value = */ obj - )); - } - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] OptionalAutomaton::equals(LSLOptional, Object) -> boolean - * Source: java/util/Optional.automata.lsl:141 - */ - public boolean equals(Object other) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (other == this) { - result = true; - } else { - final boolean isSameType = Engine.typeEquals(this, other); - if (isSameType) { - final Object otherValue = ((Optional) ((Object) other)).value; - result = LibSLRuntime.equals(this.value, otherValue); - } else { - result = false; - } - } - } - return result; - } - - /** - * [FUNCTION] OptionalAutomaton::filter(LSLOptional, Predicate) -> LSLOptional - * Source: java/util/Optional.automata.lsl:164 - */ - public Optional filter(Predicate predicate) { - Optional result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (predicate == null) { - throw new NullPointerException(); - } - if (this.value == null) { - result = this; - } else { - final boolean sat = predicate.test(this.value); - if (sat) { - result = this; - } else { - result = ((Optional) ((Object) EMPTY)); - } - } - } - return result; - } - - /** - * [FUNCTION] OptionalAutomaton::flatMap(LSLOptional, Function) -> Optional - * Source: java/util/Optional.automata.lsl:189 - */ - public java.util.Optional flatMap(Function mapper) { - java.util.Optional result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (mapper == null) { - throw new NullPointerException(); - } - if (this.value == null) { - result = EMPTY; - } else { - result = ((java.util.Optional) mapper.apply(this.value)); - if (result == null) { - throw new NullPointerException(); - } - } - } - return result; - } - - /** - * [FUNCTION] OptionalAutomaton::get(LSLOptional) -> Object - * Source: java/util/Optional.automata.lsl:215 - */ - public Object get() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.value == null) { - throw new NoSuchElementException("No value present"); - } - result = this.value; - } - return result; - } - - /** - * [FUNCTION] OptionalAutomaton::hashCode(LSLOptional) -> int - * Source: java/util/Optional.automata.lsl:224 - */ - public int hashCode() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = LibSLRuntime.hashCode(this.value); - } - return result; - } - - /** - * [FUNCTION] OptionalAutomaton::ifPresent(LSLOptional, Consumer) -> void - * Source: java/util/Optional.automata.lsl:231 - */ - public void ifPresent(Consumer consumer) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.value != null) { - if (consumer == null) { - throw new NullPointerException(); - } - consumer.accept(this.value); - } - } - } - - /** - * [FUNCTION] OptionalAutomaton::ifPresentOrElse(LSLOptional, Consumer, Runnable) -> void - * Source: java/util/Optional.automata.lsl:246 - */ - public void ifPresentOrElse(Consumer consumer, Runnable emptyAction) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.value != null) { - if (consumer == null) { - throw new NullPointerException(); - } - consumer.accept(this.value); - } else { - if (emptyAction == null) { - throw new NullPointerException(); - } - emptyAction.run(); - } - } - } - - /** - * [FUNCTION] OptionalAutomaton::isEmpty(LSLOptional) -> boolean - * Source: java/util/Optional.automata.lsl:270 - */ - public boolean isEmpty() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value == null; - } - return result; - } - - /** - * [FUNCTION] OptionalAutomaton::isPresent(LSLOptional) -> boolean - * Source: java/util/Optional.automata.lsl:276 - */ - public boolean isPresent() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value != null; - } - return result; - } - - /** - * [FUNCTION] OptionalAutomaton::map(LSLOptional, Function) -> Optional - * Source: java/util/Optional.automata.lsl:282 - */ - public java.util.Optional map(Function mapper) { - java.util.Optional result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (mapper == null) { - throw new NullPointerException(); - } - if (this.value == null) { - result = EMPTY; - } else { - final Object mappedValue = mapper.apply(this.value); - if (mappedValue == null) { - result = EMPTY; - } else { - result = (java.util.Optional) ((Object) new Optional((Void) null, - /* state = */ Optional.__$lsl_States.Initialized, - /* value = */ mappedValue - )); - } - } - } - return result; - } - - /** - * [FUNCTION] OptionalAutomaton::or(LSLOptional, Supplier) -> LSLOptional - * Source: java/util/Optional.automata.lsl:312 - */ - public Optional or(Supplier supplier) { - Optional result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (supplier == null) { - throw new NullPointerException(); - } - if (this.value == null) { - result = ((Optional) supplier.get()); - if (result == null) { - throw new NullPointerException(); - } - } else { - result = this; - } - } - return result; - } - - /** - * [FUNCTION] OptionalAutomaton::orElse(LSLOptional, Object) -> Object - * Source: java/util/Optional.automata.lsl:335 - */ - public Object orElse(Object other) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.value == null) { - result = other; - } else { - result = this.value; - } - } - return result; - } - - /** - * [FUNCTION] OptionalAutomaton::orElseGet(LSLOptional, Supplier) -> Object - * Source: java/util/Optional.automata.lsl:344 - */ - public Object orElseGet(Supplier supplier) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.value == null) { - result = supplier.get(); - } else { - result = this.value; - } - } - return result; - } - - /** - * [FUNCTION] OptionalAutomaton::orElseThrow(LSLOptional) -> Object - * Source: java/util/Optional.automata.lsl:356 - */ - public Object orElseThrow() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.value == null) { - throw new NoSuchElementException("No value present"); - } - result = this.value; - } - return result; - } - - /** - * [FUNCTION] OptionalAutomaton::orElseThrow(LSLOptional, Supplier) -> Object - * Source: java/util/Optional.automata.lsl:367 - */ - public Object orElseThrow(Supplier exceptionSupplier) throws java.lang.Throwable { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (exceptionSupplier == null) { - throw new NullPointerException(); - } - if (this.value == null) { - final Object exception = exceptionSupplier.get(); - throw ((Throwable) exception); - } else { - result = this.value; - } - } - return result; - } - - /** - * [FUNCTION] OptionalAutomaton::stream(LSLOptional) -> Stream - * Source: java/util/Optional.automata.lsl:389 - */ - public Stream stream() { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Object[] items = null; - if (this.value == null) { - items = new Object[0]; - } else { - items = new Object[1]; - items[0] = this.value; - } - result = (StreamLSL) ((Object) new generated.java.util.stream.StreamLSL((Void) null, - /* state = */ generated.java.util.stream.StreamLSL.__$lsl_States.Initialized, - /* storage = */ items, - /* length = */ items.length, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] OptionalAutomaton::toString(LSLOptional) -> String - * Source: java/util/Optional.automata.lsl:412 - */ - public String toString() { - String result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.value == null) { - result = "Optional.empty"; - } else { - final String valueStr = LibSLRuntime.toString(this.value); - result = "Optional[".concat(valueStr).concat("]"); - } - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(Optional.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/OptionalDouble.java b/approximations/src/main/java/generated/java/util/OptionalDouble.java deleted file mode 100644 index ab612922..00000000 --- a/approximations/src/main/java/generated/java/util/OptionalDouble.java +++ /dev/null @@ -1,370 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/OptionalDouble.lsl:36 -// - java/util/OptionalDouble.automata.lsl:22 -// -package generated.java.util; - -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.Runnable; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.NoSuchElementException; -import java.util.function.DoubleConsumer; -import java.util.function.DoubleSupplier; -import java.util.function.Supplier; -import java.util.stream.DoubleStream; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; -import stub.java.util.stream.DoubleStreamLSL; - -/** - * OptionalDoubleAutomaton for LSLOptionalDouble ~> java.util.OptionalDouble - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.util.OptionalDouble.class) -public final class OptionalDouble implements LibSLRuntime.Automaton { - private static java.util.OptionalDouble EMPTY = null; - - static { - /* OptionalDoubleAutomaton::() */ { - EMPTY = (java.util.OptionalDouble) ((Object) new OptionalDouble((Void) null, - /* state = */ OptionalDouble.__$lsl_States.Initialized, - /* value = */ 0.0d, - /* present = */ false - )); - } - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public double value; - - public boolean present; - - @LibSLRuntime.AutomatonConstructor - public OptionalDouble(Void __$lsl_token, final byte p0, final double p1, final boolean p2) { - this.__$lsl_state = p0; - this.value = p1; - this.present = p2; - } - - @LibSLRuntime.AutomatonConstructor - public OptionalDouble(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, 0.0d, false); - } - - /** - * [CONSTRUCTOR] OptionalDoubleAutomaton::(LSLOptionalDouble) -> void - * Source: java/util/OptionalDouble.automata.lsl:72 - */ - private OptionalDouble() { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - LibSLRuntime.not_implemented(/* this method can be called using reflection only */); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] OptionalDoubleAutomaton::(LSLOptionalDouble, double) -> void - * Source: java/util/OptionalDouble.automata.lsl:78 - */ - private OptionalDouble(double x) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - LibSLRuntime.not_implemented(/* this method can be called using reflection only */); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [FUNCTION] OptionalDoubleAutomaton::empty() -> OptionalDouble - * Source: java/util/OptionalDouble.automata.lsl:86 - */ - public static java.util.OptionalDouble empty() { - java.util.OptionalDouble result = null; - // WARNING: no state checks in static context - /* body */ { - result = EMPTY; - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] OptionalDoubleAutomaton::of(double) -> OptionalDouble - * Source: java/util/OptionalDouble.automata.lsl:92 - */ - public static java.util.OptionalDouble of(double x) { - java.util.OptionalDouble result = null; - // WARNING: no state checks in static context - /* body */ { - result = (java.util.OptionalDouble) ((Object) new OptionalDouble((Void) null, - /* state = */ OptionalDouble.__$lsl_States.Initialized, - /* value = */ x, - /* present = */ true - )); - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] OptionalDoubleAutomaton::equals(LSLOptionalDouble, Object) -> boolean - * Source: java/util/OptionalDouble.automata.lsl:103 - */ - public boolean equals(Object other) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (other == this) { - result = true; - } else { - final boolean isSameType = Engine.typeEquals(this, other); - if (isSameType) { - final double otherValue = ((OptionalDouble) ((Object) other)).value; - final boolean otherPresent = ((OptionalDouble) ((Object) other)).present; - if (this.present && otherPresent) { - result = LibSLRuntime.equals(this.value, otherValue); - } else { - result = this.present == otherPresent; - } - } else { - result = false; - } - } - } - return result; - } - - /** - * [FUNCTION] OptionalDoubleAutomaton::getAsDouble(LSLOptionalDouble) -> double - * Source: java/util/OptionalDouble.automata.lsl:131 - */ - public double getAsDouble() { - double result = 0.0d; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (!this.present) { - throw new NoSuchElementException("No value present"); - } - result = this.value; - } - return result; - } - - /** - * [FUNCTION] OptionalDoubleAutomaton::hashCode(LSLOptionalDouble) -> int - * Source: java/util/OptionalDouble.automata.lsl:140 - */ - public int hashCode() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.present) { - result = LibSLRuntime.hashCode(this.value); - } else { - result = 0; - } - } - return result; - } - - /** - * [FUNCTION] OptionalDoubleAutomaton::ifPresent(LSLOptionalDouble, DoubleConsumer) -> void - * Source: java/util/OptionalDouble.automata.lsl:150 - */ - public void ifPresent(DoubleConsumer consumer) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.present) { - if (consumer == null) { - throw new NullPointerException(); - } - consumer.accept(this.value); - } - } - } - - /** - * [FUNCTION] OptionalDoubleAutomaton::ifPresentOrElse(LSLOptionalDouble, DoubleConsumer, Runnable) -> void - * Source: java/util/OptionalDouble.automata.lsl:164 - */ - public void ifPresentOrElse(DoubleConsumer consumer, Runnable emptyAction) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.present) { - if (consumer == null) { - throw new NullPointerException(); - } - consumer.accept(this.value); - } else { - if (emptyAction == null) { - throw new NullPointerException(); - } - emptyAction.run(); - } - } - } - - /** - * [FUNCTION] OptionalDoubleAutomaton::isEmpty(LSLOptionalDouble) -> boolean - * Source: java/util/OptionalDouble.automata.lsl:186 - */ - public boolean isEmpty() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = !this.present; - } - return result; - } - - /** - * [FUNCTION] OptionalDoubleAutomaton::isPresent(LSLOptionalDouble) -> boolean - * Source: java/util/OptionalDouble.automata.lsl:192 - */ - public boolean isPresent() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.present; - } - return result; - } - - /** - * [FUNCTION] OptionalDoubleAutomaton::orElse(LSLOptionalDouble, double) -> double - * Source: java/util/OptionalDouble.automata.lsl:198 - */ - public double orElse(double other) { - double result = 0.0d; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.present) { - result = this.value; - } else { - result = other; - } - } - return result; - } - - /** - * [FUNCTION] OptionalDoubleAutomaton::orElseGet(LSLOptionalDouble, DoubleSupplier) -> double - * Source: java/util/OptionalDouble.automata.lsl:207 - */ - public double orElseGet(DoubleSupplier supplier) { - double result = 0.0d; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.present) { - result = this.value; - } else { - result = supplier.getAsDouble(); - } - } - return result; - } - - /** - * [FUNCTION] OptionalDoubleAutomaton::orElseThrow(LSLOptionalDouble) -> double - * Source: java/util/OptionalDouble.automata.lsl:218 - */ - public double orElseThrow() { - double result = 0.0d; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (!this.present) { - throw new NoSuchElementException("No value present"); - } - result = this.value; - } - return result; - } - - /** - * [FUNCTION] OptionalDoubleAutomaton::orElseThrow(LSLOptionalDouble, Supplier) -> double - * Source: java/util/OptionalDouble.automata.lsl:229 - */ - public double orElseThrow(Supplier exceptionSupplier) throws java.lang.Throwable { - double result = 0.0d; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (exceptionSupplier == null) { - throw new NullPointerException(); - } - if (!this.present) { - final Object exception = exceptionSupplier.get(); - throw ((Throwable) exception); - } else { - result = this.value; - } - } - return result; - } - - /** - * [FUNCTION] OptionalDoubleAutomaton::stream(LSLOptionalDouble) -> DoubleStream - * Source: java/util/OptionalDouble.automata.lsl:250 - */ - public DoubleStream stream() { - DoubleStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - double[] items = null; - if (this.present) { - items = new double[1]; - items[0] = this.value; - } else { - items = new double[0]; - } - result = (DoubleStreamLSL) ((Object) new generated.java.util.stream.DoubleStreamLSL((Void) null, - /* state = */ generated.java.util.stream.DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ items, - /* length = */ items.length, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] OptionalDoubleAutomaton::toString(LSLOptionalDouble) -> String - * Source: java/util/OptionalDouble.automata.lsl:272 - */ - public String toString() { - String result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.present) { - final String valueStr = LibSLRuntime.toString(this.value); - result = "OptionalDouble[".concat(valueStr).concat("]"); - } else { - result = "OptionalDouble.empty"; - } - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(OptionalDouble.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/OptionalInt.java b/approximations/src/main/java/generated/java/util/OptionalInt.java deleted file mode 100644 index 2ee5568b..00000000 --- a/approximations/src/main/java/generated/java/util/OptionalInt.java +++ /dev/null @@ -1,370 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/OptionalInt.lsl:36 -// - java/util/OptionalInt.automata.lsl:22 -// -package generated.java.util; - -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.Runnable; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.NoSuchElementException; -import java.util.function.IntConsumer; -import java.util.function.IntSupplier; -import java.util.function.Supplier; -import java.util.stream.IntStream; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; -import stub.java.util.stream.IntStreamLSL; - -/** - * OptionalIntAutomaton for LSLOptionalInt ~> java.util.OptionalInt - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.util.OptionalInt.class) -public final class OptionalInt implements LibSLRuntime.Automaton { - private static java.util.OptionalInt EMPTY = null; - - static { - /* OptionalIntAutomaton::() */ { - EMPTY = (java.util.OptionalInt) ((Object) new OptionalInt((Void) null, - /* state = */ OptionalInt.__$lsl_States.Initialized, - /* value = */ 0, - /* present = */ false - )); - } - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public int value; - - public boolean present; - - @LibSLRuntime.AutomatonConstructor - public OptionalInt(Void __$lsl_token, final byte p0, final int p1, final boolean p2) { - this.__$lsl_state = p0; - this.value = p1; - this.present = p2; - } - - @LibSLRuntime.AutomatonConstructor - public OptionalInt(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, 0, false); - } - - /** - * [CONSTRUCTOR] OptionalIntAutomaton::(LSLOptionalInt) -> void - * Source: java/util/OptionalInt.automata.lsl:72 - */ - private OptionalInt() { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - LibSLRuntime.not_implemented(/* this method can be called using reflection only */); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] OptionalIntAutomaton::(LSLOptionalInt, int) -> void - * Source: java/util/OptionalInt.automata.lsl:78 - */ - private OptionalInt(int x) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - LibSLRuntime.not_implemented(/* this method can be called using reflection only */); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [FUNCTION] OptionalIntAutomaton::empty() -> OptionalInt - * Source: java/util/OptionalInt.automata.lsl:86 - */ - public static java.util.OptionalInt empty() { - java.util.OptionalInt result = null; - // WARNING: no state checks in static context - /* body */ { - result = EMPTY; - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] OptionalIntAutomaton::of(int) -> OptionalInt - * Source: java/util/OptionalInt.automata.lsl:92 - */ - public static java.util.OptionalInt of(int x) { - java.util.OptionalInt result = null; - // WARNING: no state checks in static context - /* body */ { - result = (java.util.OptionalInt) ((Object) new OptionalInt((Void) null, - /* state = */ OptionalInt.__$lsl_States.Initialized, - /* value = */ x, - /* present = */ true - )); - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] OptionalIntAutomaton::equals(LSLOptionalInt, Object) -> boolean - * Source: java/util/OptionalInt.automata.lsl:103 - */ - public boolean equals(Object other) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (other == this) { - result = true; - } else { - final boolean isSameType = Engine.typeEquals(this, other); - if (isSameType) { - final int otherValue = ((OptionalInt) ((Object) other)).value; - final boolean otherPresent = ((OptionalInt) ((Object) other)).present; - if (this.present && otherPresent) { - result = this.value == otherValue; - } else { - result = this.present == otherPresent; - } - } else { - result = false; - } - } - } - return result; - } - - /** - * [FUNCTION] OptionalIntAutomaton::getAsInt(LSLOptionalInt) -> int - * Source: java/util/OptionalInt.automata.lsl:131 - */ - public int getAsInt() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (!this.present) { - throw new NoSuchElementException("No value present"); - } - result = this.value; - } - return result; - } - - /** - * [FUNCTION] OptionalIntAutomaton::hashCode(LSLOptionalInt) -> int - * Source: java/util/OptionalInt.automata.lsl:140 - */ - public int hashCode() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.present) { - result = LibSLRuntime.hashCode(this.value); - } else { - result = 0; - } - } - return result; - } - - /** - * [FUNCTION] OptionalIntAutomaton::ifPresent(LSLOptionalInt, IntConsumer) -> void - * Source: java/util/OptionalInt.automata.lsl:150 - */ - public void ifPresent(IntConsumer consumer) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.present) { - if (consumer == null) { - throw new NullPointerException(); - } - consumer.accept(this.value); - } - } - } - - /** - * [FUNCTION] OptionalIntAutomaton::ifPresentOrElse(LSLOptionalInt, IntConsumer, Runnable) -> void - * Source: java/util/OptionalInt.automata.lsl:164 - */ - public void ifPresentOrElse(IntConsumer consumer, Runnable emptyAction) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.present) { - if (consumer == null) { - throw new NullPointerException(); - } - consumer.accept(this.value); - } else { - if (emptyAction == null) { - throw new NullPointerException(); - } - emptyAction.run(); - } - } - } - - /** - * [FUNCTION] OptionalIntAutomaton::isEmpty(LSLOptionalInt) -> boolean - * Source: java/util/OptionalInt.automata.lsl:186 - */ - public boolean isEmpty() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = !this.present; - } - return result; - } - - /** - * [FUNCTION] OptionalIntAutomaton::isPresent(LSLOptionalInt) -> boolean - * Source: java/util/OptionalInt.automata.lsl:192 - */ - public boolean isPresent() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.present; - } - return result; - } - - /** - * [FUNCTION] OptionalIntAutomaton::orElse(LSLOptionalInt, int) -> int - * Source: java/util/OptionalInt.automata.lsl:198 - */ - public int orElse(int other) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.present) { - result = this.value; - } else { - result = other; - } - } - return result; - } - - /** - * [FUNCTION] OptionalIntAutomaton::orElseGet(LSLOptionalInt, IntSupplier) -> int - * Source: java/util/OptionalInt.automata.lsl:207 - */ - public int orElseGet(IntSupplier supplier) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.present) { - result = this.value; - } else { - result = supplier.getAsInt(); - } - } - return result; - } - - /** - * [FUNCTION] OptionalIntAutomaton::orElseThrow(LSLOptionalInt) -> int - * Source: java/util/OptionalInt.automata.lsl:218 - */ - public int orElseThrow() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (!this.present) { - throw new NoSuchElementException("No value present"); - } - result = this.value; - } - return result; - } - - /** - * [FUNCTION] OptionalIntAutomaton::orElseThrow(LSLOptionalInt, Supplier) -> int - * Source: java/util/OptionalInt.automata.lsl:229 - */ - public int orElseThrow(Supplier exceptionSupplier) throws java.lang.Throwable { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (exceptionSupplier == null) { - throw new NullPointerException(); - } - if (!this.present) { - final Object exception = exceptionSupplier.get(); - throw ((Throwable) exception); - } else { - result = this.value; - } - } - return result; - } - - /** - * [FUNCTION] OptionalIntAutomaton::stream(LSLOptionalInt) -> IntStream - * Source: java/util/OptionalInt.automata.lsl:250 - */ - public IntStream stream() { - IntStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - int[] items = null; - if (this.present) { - items = new int[1]; - items[0] = this.value; - } else { - items = new int[0]; - } - result = (IntStreamLSL) ((Object) new generated.java.util.stream.IntStreamLSL((Void) null, - /* state = */ generated.java.util.stream.IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ items, - /* length = */ items.length, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] OptionalIntAutomaton::toString(LSLOptionalInt) -> String - * Source: java/util/OptionalInt.automata.lsl:272 - */ - public String toString() { - String result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.present) { - final String valueStr = LibSLRuntime.toString(this.value); - result = "OptionalInt[".concat(valueStr).concat("]"); - } else { - result = "OptionalInt.empty"; - } - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(OptionalInt.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/OptionalLong.java b/approximations/src/main/java/generated/java/util/OptionalLong.java deleted file mode 100644 index ccd143b4..00000000 --- a/approximations/src/main/java/generated/java/util/OptionalLong.java +++ /dev/null @@ -1,370 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/OptionalLong.lsl:36 -// - java/util/OptionalLong.automata.lsl:22 -// -package generated.java.util; - -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.Runnable; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.NoSuchElementException; -import java.util.function.LongConsumer; -import java.util.function.LongSupplier; -import java.util.function.Supplier; -import java.util.stream.LongStream; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; -import stub.java.util.stream.LongStreamLSL; - -/** - * OptionalLongAutomaton for LSLOptionalLong ~> java.util.OptionalLong - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.util.OptionalLong.class) -public final class OptionalLong implements LibSLRuntime.Automaton { - private static java.util.OptionalLong EMPTY = null; - - static { - /* OptionalLongAutomaton::() */ { - EMPTY = (java.util.OptionalLong) ((Object) new OptionalLong((Void) null, - /* state = */ OptionalLong.__$lsl_States.Initialized, - /* value = */ 0L, - /* present = */ false - )); - } - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public long value; - - public boolean present; - - @LibSLRuntime.AutomatonConstructor - public OptionalLong(Void __$lsl_token, final byte p0, final long p1, final boolean p2) { - this.__$lsl_state = p0; - this.value = p1; - this.present = p2; - } - - @LibSLRuntime.AutomatonConstructor - public OptionalLong(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, 0L, false); - } - - /** - * [CONSTRUCTOR] OptionalLongAutomaton::(LSLOptionalLong) -> void - * Source: java/util/OptionalLong.automata.lsl:72 - */ - private OptionalLong() { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - LibSLRuntime.not_implemented(/* this method can be called using reflection only */); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] OptionalLongAutomaton::(LSLOptionalLong, long) -> void - * Source: java/util/OptionalLong.automata.lsl:78 - */ - private OptionalLong(long x) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - LibSLRuntime.not_implemented(/* this method can be called using reflection only */); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [FUNCTION] OptionalLongAutomaton::empty() -> OptionalLong - * Source: java/util/OptionalLong.automata.lsl:86 - */ - public static java.util.OptionalLong empty() { - java.util.OptionalLong result = null; - // WARNING: no state checks in static context - /* body */ { - result = EMPTY; - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] OptionalLongAutomaton::of(long) -> OptionalLong - * Source: java/util/OptionalLong.automata.lsl:92 - */ - public static java.util.OptionalLong of(long x) { - java.util.OptionalLong result = null; - // WARNING: no state checks in static context - /* body */ { - result = (java.util.OptionalLong) ((Object) new OptionalLong((Void) null, - /* state = */ OptionalLong.__$lsl_States.Initialized, - /* value = */ x, - /* present = */ true - )); - } - // WARNING: no state transitions in static context - return result; - } - - /** - * [FUNCTION] OptionalLongAutomaton::equals(LSLOptionalLong, Object) -> boolean - * Source: java/util/OptionalLong.automata.lsl:103 - */ - public boolean equals(Object other) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (other == this) { - result = true; - } else { - final boolean isSameType = Engine.typeEquals(this, other); - if (isSameType) { - final long otherValue = ((OptionalLong) ((Object) other)).value; - final boolean otherPresent = ((OptionalLong) ((Object) other)).present; - if (this.present && otherPresent) { - result = this.value == otherValue; - } else { - result = this.present == otherPresent; - } - } else { - result = false; - } - } - } - return result; - } - - /** - * [FUNCTION] OptionalLongAutomaton::getAsLong(LSLOptionalLong) -> long - * Source: java/util/OptionalLong.automata.lsl:131 - */ - public long getAsLong() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (!this.present) { - throw new NoSuchElementException("No value present"); - } - result = this.value; - } - return result; - } - - /** - * [FUNCTION] OptionalLongAutomaton::hashCode(LSLOptionalLong) -> int - * Source: java/util/OptionalLong.automata.lsl:140 - */ - public int hashCode() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.present) { - result = LibSLRuntime.hashCode(this.value); - } else { - result = 0; - } - } - return result; - } - - /** - * [FUNCTION] OptionalLongAutomaton::ifPresent(LSLOptionalLong, LongConsumer) -> void - * Source: java/util/OptionalLong.automata.lsl:150 - */ - public void ifPresent(LongConsumer consumer) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.present) { - if (consumer == null) { - throw new NullPointerException(); - } - consumer.accept(this.value); - } - } - } - - /** - * [FUNCTION] OptionalLongAutomaton::ifPresentOrElse(LSLOptionalLong, LongConsumer, Runnable) -> void - * Source: java/util/OptionalLong.automata.lsl:164 - */ - public void ifPresentOrElse(LongConsumer consumer, Runnable emptyAction) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.present) { - if (consumer == null) { - throw new NullPointerException(); - } - consumer.accept(this.value); - } else { - if (emptyAction == null) { - throw new NullPointerException(); - } - emptyAction.run(); - } - } - } - - /** - * [FUNCTION] OptionalLongAutomaton::isEmpty(LSLOptionalLong) -> boolean - * Source: java/util/OptionalLong.automata.lsl:186 - */ - public boolean isEmpty() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = !this.present; - } - return result; - } - - /** - * [FUNCTION] OptionalLongAutomaton::isPresent(LSLOptionalLong) -> boolean - * Source: java/util/OptionalLong.automata.lsl:192 - */ - public boolean isPresent() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.present; - } - return result; - } - - /** - * [FUNCTION] OptionalLongAutomaton::orElse(LSLOptionalLong, long) -> long - * Source: java/util/OptionalLong.automata.lsl:198 - */ - public long orElse(long other) { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.present) { - result = this.value; - } else { - result = other; - } - } - return result; - } - - /** - * [FUNCTION] OptionalLongAutomaton::orElseGet(LSLOptionalLong, LongSupplier) -> long - * Source: java/util/OptionalLong.automata.lsl:207 - */ - public long orElseGet(LongSupplier supplier) { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.present) { - result = this.value; - } else { - result = supplier.getAsLong(); - } - } - return result; - } - - /** - * [FUNCTION] OptionalLongAutomaton::orElseThrow(LSLOptionalLong) -> long - * Source: java/util/OptionalLong.automata.lsl:218 - */ - public long orElseThrow() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (!this.present) { - throw new NoSuchElementException("No value present"); - } - result = this.value; - } - return result; - } - - /** - * [FUNCTION] OptionalLongAutomaton::orElseThrow(LSLOptionalLong, Supplier) -> long - * Source: java/util/OptionalLong.automata.lsl:229 - */ - public long orElseThrow(Supplier exceptionSupplier) throws java.lang.Throwable { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (exceptionSupplier == null) { - throw new NullPointerException(); - } - if (!this.present) { - final Object exception = exceptionSupplier.get(); - throw ((Throwable) exception); - } else { - result = this.value; - } - } - return result; - } - - /** - * [FUNCTION] OptionalLongAutomaton::stream(LSLOptionalLong) -> LongStream - * Source: java/util/OptionalLong.automata.lsl:250 - */ - public LongStream stream() { - LongStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - long[] items = null; - if (this.present) { - items = new long[1]; - items[0] = this.value; - } else { - items = new long[0]; - } - result = (LongStreamLSL) ((Object) new generated.java.util.stream.LongStreamLSL((Void) null, - /* state = */ generated.java.util.stream.LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ items, - /* length = */ items.length, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] OptionalLongAutomaton::toString(LSLOptionalLong) -> String - * Source: java/util/OptionalLong.automata.lsl:272 - */ - public String toString() { - String result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.present) { - final String valueStr = LibSLRuntime.toString(this.value); - result = "OptionalLong[".concat(valueStr).concat("]"); - } else { - result = "OptionalLong.empty"; - } - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(OptionalLong.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/Random.java b/approximations/src/main/java/generated/java/util/Random.java deleted file mode 100644 index 8eae9ee3..00000000 --- a/approximations/src/main/java/generated/java/util/Random.java +++ /dev/null @@ -1,607 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/Random.lsl:16 -// - java/util/Random.main.lsl:21 -// -package generated.java.util; - -import generated.runtime.LibSLGlobals; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.ObjectStreamField; -import java.io.Serializable; -import java.lang.IllegalArgumentException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.stream.DoubleStream; -import java.util.stream.IntStream; -import java.util.stream.LongStream; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; -import stub.java.util.stream.DoubleStreamLSL; -import stub.java.util.stream.IntStreamLSL; -import stub.java.util.stream.LongStreamLSL; - -/** - * RandomAutomaton for Random ~> java.util.Random - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.util.Random.class) -public class Random implements LibSLRuntime.Automaton, Serializable { - private static final long serialVersionUID = 3905348978240129619L; - - private static final ObjectStreamField[] serialPersistentFields = {}; - - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - @LibSLRuntime.AutomatonConstructor - public Random(Void __$lsl_token, final byte p0) { - this.__$lsl_state = p0; - } - - @LibSLRuntime.AutomatonConstructor - public Random(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated); - } - - /** - * [CONSTRUCTOR] RandomAutomaton::(Random) -> void - * Source: java/util/Random.main.lsl:137 - */ - public Random() { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - Engine.assume(true); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] RandomAutomaton::(Random, long) -> void - * Source: java/util/Random.main.lsl:143 - */ - public Random(long seed) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - Engine.assume(true); - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] RandomAutomaton::_nextBytes(array, int) -> void - * Source: java/util/Random.main.lsl:72 - */ - private static void _nextBytes(byte[] result, int numBytes) { - /* body */ { - final byte[] symbolicArray = Engine.makeSymbolicByteArray(numBytes); - LibSLRuntime.ArrayActions.copy(symbolicArray, 0, result, 0, numBytes); - } - } - - /** - * [SUBROUTINE] RandomAutomaton::_generateRandomIntegerArrayWithBounds(int, int, int) -> array - * Source: java/util/Random.main.lsl:79 - */ - private int[] _generateRandomIntegerArrayWithBounds(int size, int randomNumberOrigin, - int randomNumberBound) { - int[] result = null; - /* body */ { - result = Engine.makeSymbolicIntArray(size); - int i = 0; - for (i = 0; i < size; i += 1) { - Engine.assume(result[i] >= randomNumberOrigin); - Engine.assume(result[i] < randomNumberBound); - } - ; - } - return result; - } - - /** - * [SUBROUTINE] RandomAutomaton::_generateRandomLongArrayWithBounds(int, long, long) -> array - * Source: java/util/Random.main.lsl:97 - */ - private long[] _generateRandomLongArrayWithBounds(int size, long randomNumberOrigin, - long randomNumberBound) { - long[] result = null; - /* body */ { - result = Engine.makeSymbolicLongArray(size); - int i = 0; - for (i = 0; i < size; i += 1) { - Engine.assume(result[i] >= randomNumberOrigin); - Engine.assume(result[i] < randomNumberBound); - } - ; - } - return result; - } - - /** - * [SUBROUTINE] RandomAutomaton::_generateRandomDoubleArrayWithBounds(int, double, double) -> array - * Source: java/util/Random.main.lsl:115 - */ - private double[] _generateRandomDoubleArrayWithBounds(int size, double randomNumberOrigin, - double randomNumberBound) { - double[] result = null; - /* body */ { - result = Engine.makeSymbolicDoubleArray(size); - int i = 0; - for (i = 0; i < size; i += 1) { - final double item = result[i]; - Engine.assume(item == item); - Engine.assume(item >= randomNumberOrigin); - Engine.assume(item < randomNumberBound); - } - ; - } - return result; - } - - /** - * [FUNCTION] RandomAutomaton::doubles(Random) -> DoubleStream - * Source: java/util/Random.main.lsl:153 - */ - public DoubleStream doubles() { - DoubleStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (DoubleStreamLSL) ((Object) new generated.java.util.stream.DoubleStreamLSL((Void) null, - /* state = */ generated.java.util.stream.DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ _generateRandomDoubleArrayWithBounds(LibSLGlobals.RANDOM_STREAM_SIZE_MAX, 0, 1), - /* length = */ LibSLGlobals.RANDOM_STREAM_SIZE_MAX, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] RandomAutomaton::doubles(Random, double, double) -> DoubleStream - * Source: java/util/Random.main.lsl:163 - */ - public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound) { - DoubleStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (randomNumberOrigin >= randomNumberBound) { - throw new IllegalArgumentException(); - } - result = (DoubleStreamLSL) ((Object) new generated.java.util.stream.DoubleStreamLSL((Void) null, - /* state = */ generated.java.util.stream.DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ _generateRandomDoubleArrayWithBounds(LibSLGlobals.RANDOM_STREAM_SIZE_MAX, randomNumberOrigin, randomNumberBound), - /* length = */ LibSLGlobals.RANDOM_STREAM_SIZE_MAX, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] RandomAutomaton::doubles(Random, long) -> DoubleStream - * Source: java/util/Random.main.lsl:175 - */ - public DoubleStream doubles(long streamSize) { - DoubleStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - int size = ((int) streamSize); - if (size < 0) { - throw new IllegalArgumentException(); - } - if (size > LibSLGlobals.RANDOM_STREAM_SIZE_MAX) { - size = LibSLGlobals.RANDOM_STREAM_SIZE_MAX; - } - result = (DoubleStreamLSL) ((Object) new generated.java.util.stream.DoubleStreamLSL((Void) null, - /* state = */ generated.java.util.stream.DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ Engine.makeSymbolicDoubleArray(size), - /* length = */ size, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] RandomAutomaton::doubles(Random, long, double, double) -> DoubleStream - * Source: java/util/Random.main.lsl:192 - */ - public DoubleStream doubles(long streamSize, double randomNumberOrigin, - double randomNumberBound) { - DoubleStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - int size = ((int) streamSize); - if (size < 0) { - throw new IllegalArgumentException(); - } - if (randomNumberOrigin >= randomNumberBound) { - throw new IllegalArgumentException(); - } - if (size > LibSLGlobals.RANDOM_STREAM_SIZE_MAX) { - size = LibSLGlobals.RANDOM_STREAM_SIZE_MAX; - } - result = (DoubleStreamLSL) ((Object) new generated.java.util.stream.DoubleStreamLSL((Void) null, - /* state = */ generated.java.util.stream.DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ _generateRandomDoubleArrayWithBounds(size, randomNumberOrigin, randomNumberBound), - /* length = */ size, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] RandomAutomaton::ints(Random) -> IntStream - * Source: java/util/Random.main.lsl:211 - */ - public IntStream ints() { - IntStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (IntStreamLSL) ((Object) new generated.java.util.stream.IntStreamLSL((Void) null, - /* state = */ generated.java.util.stream.IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ Engine.makeSymbolicIntArray(LibSLGlobals.RANDOM_STREAM_SIZE_MAX), - /* length = */ LibSLGlobals.RANDOM_STREAM_SIZE_MAX, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] RandomAutomaton::ints(Random, int, int) -> IntStream - * Source: java/util/Random.main.lsl:221 - */ - public IntStream ints(int randomNumberOrigin, int randomNumberBound) { - IntStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (randomNumberOrigin >= randomNumberBound) { - throw new IllegalArgumentException(); - } - result = (IntStreamLSL) ((Object) new generated.java.util.stream.IntStreamLSL((Void) null, - /* state = */ generated.java.util.stream.IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ _generateRandomIntegerArrayWithBounds(LibSLGlobals.RANDOM_STREAM_SIZE_MAX, randomNumberOrigin, randomNumberBound), - /* length = */ LibSLGlobals.RANDOM_STREAM_SIZE_MAX, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] RandomAutomaton::ints(Random, long) -> IntStream - * Source: java/util/Random.main.lsl:233 - */ - public IntStream ints(long streamSize) { - IntStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - int size = ((int) streamSize); - if (size < 0) { - throw new IllegalArgumentException(); - } - if (size > LibSLGlobals.RANDOM_STREAM_SIZE_MAX) { - size = LibSLGlobals.RANDOM_STREAM_SIZE_MAX; - } - result = (IntStreamLSL) ((Object) new generated.java.util.stream.IntStreamLSL((Void) null, - /* state = */ generated.java.util.stream.IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ Engine.makeSymbolicIntArray(size), - /* length = */ size, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] RandomAutomaton::ints(Random, long, int, int) -> IntStream - * Source: java/util/Random.main.lsl:250 - */ - public IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberBound) { - IntStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - int size = ((int) streamSize); - if (size < 0) { - throw new IllegalArgumentException(); - } - if (randomNumberOrigin >= randomNumberBound) { - throw new IllegalArgumentException(); - } - if (size > LibSLGlobals.RANDOM_STREAM_SIZE_MAX) { - size = LibSLGlobals.RANDOM_STREAM_SIZE_MAX; - } - result = (IntStreamLSL) ((Object) new generated.java.util.stream.IntStreamLSL((Void) null, - /* state = */ generated.java.util.stream.IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ _generateRandomIntegerArrayWithBounds(size, randomNumberOrigin, randomNumberBound), - /* length = */ size, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] RandomAutomaton::longs(Random) -> LongStream - * Source: java/util/Random.main.lsl:269 - */ - public LongStream longs() { - LongStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = (LongStreamLSL) ((Object) new generated.java.util.stream.LongStreamLSL((Void) null, - /* state = */ generated.java.util.stream.LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ Engine.makeSymbolicLongArray(LibSLGlobals.RANDOM_STREAM_SIZE_MAX), - /* length = */ LibSLGlobals.RANDOM_STREAM_SIZE_MAX, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] RandomAutomaton::longs(Random, long) -> LongStream - * Source: java/util/Random.main.lsl:279 - */ - public LongStream longs(long streamSize) { - LongStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - int size = ((int) streamSize); - if (size < 0) { - throw new IllegalArgumentException(); - } - if (size > LibSLGlobals.RANDOM_STREAM_SIZE_MAX) { - size = LibSLGlobals.RANDOM_STREAM_SIZE_MAX; - } - result = (LongStreamLSL) ((Object) new generated.java.util.stream.LongStreamLSL((Void) null, - /* state = */ generated.java.util.stream.LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ Engine.makeSymbolicLongArray(size), - /* length = */ size, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] RandomAutomaton::longs(Random, long, long) -> LongStream - * Source: java/util/Random.main.lsl:296 - */ - public LongStream longs(long randomNumberOrigin, long randomNumberBound) { - LongStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (randomNumberOrigin >= randomNumberBound) { - throw new IllegalArgumentException(); - } - result = (LongStreamLSL) ((Object) new generated.java.util.stream.LongStreamLSL((Void) null, - /* state = */ generated.java.util.stream.LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ _generateRandomLongArrayWithBounds(LibSLGlobals.RANDOM_STREAM_SIZE_MAX, randomNumberOrigin, randomNumberBound), - /* length = */ LibSLGlobals.RANDOM_STREAM_SIZE_MAX, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] RandomAutomaton::longs(Random, long, long, long) -> LongStream - * Source: java/util/Random.main.lsl:308 - */ - public LongStream longs(long streamSize, long randomNumberOrigin, long randomNumberBound) { - LongStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - int size = ((int) streamSize); - if (size < 0) { - throw new IllegalArgumentException(); - } - if (randomNumberOrigin >= randomNumberBound) { - throw new IllegalArgumentException(); - } - if (size > LibSLGlobals.RANDOM_STREAM_SIZE_MAX) { - size = LibSLGlobals.RANDOM_STREAM_SIZE_MAX; - } - result = (LongStreamLSL) ((Object) new generated.java.util.stream.LongStreamLSL((Void) null, - /* state = */ generated.java.util.stream.LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ _generateRandomLongArrayWithBounds(size, randomNumberOrigin, randomNumberBound), - /* length = */ size, - /* closeHandlers = */ Engine.makeSymbolicList(), - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - return result; - } - - /** - * [FUNCTION] RandomAutomaton::nextBoolean(Random) -> boolean - * Source: java/util/Random.main.lsl:327 - */ - public boolean nextBoolean() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = Engine.makeSymbolicBoolean(); - } - return result; - } - - /** - * [FUNCTION] RandomAutomaton::nextBytes(Random, array) -> void - * Source: java/util/Random.main.lsl:333 - */ - public void nextBytes(byte[] bytes) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _nextBytes(bytes, bytes.length); - } - } - - /** - * [FUNCTION] RandomAutomaton::nextDouble(Random) -> double - * Source: java/util/Random.main.lsl:339 - */ - public double nextDouble() { - double result = 0.0d; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = Engine.makeSymbolicDouble(); - Engine.assume(0.0d <= result); - Engine.assume(result < 1.0d); - } - return result; - } - - /** - * [FUNCTION] RandomAutomaton::nextFloat(Random) -> float - * Source: java/util/Random.main.lsl:348 - */ - public float nextFloat() { - float result = 0.0f; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = Engine.makeSymbolicFloat(); - Engine.assume(0.0f <= result); - Engine.assume(result < 1.0f); - } - return result; - } - - /** - * [FUNCTION] RandomAutomaton::nextGaussian(Random) -> double - * Source: java/util/Random.main.lsl:357 - */ - public synchronized double nextGaussian() { - double result = 0.0d; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = Engine.makeSymbolicDouble(); - final boolean isNaN = result != result; - Engine.assume(!isNaN); - } - return result; - } - - /** - * [FUNCTION] RandomAutomaton::nextInt(Random) -> int - * Source: java/util/Random.main.lsl:365 - */ - public int nextInt() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = Engine.makeSymbolicInt(); - } - return result; - } - - /** - * [FUNCTION] RandomAutomaton::nextInt(Random, int) -> int - * Source: java/util/Random.main.lsl:371 - */ - public int nextInt(int bound) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (bound <= 0) { - throw new IllegalArgumentException("bound must be positive"); - } - result = Engine.makeSymbolicInt(); - Engine.assume(0 <= result); - Engine.assume(result < bound); - } - return result; - } - - /** - * [FUNCTION] RandomAutomaton::nextLong(Random) -> long - * Source: java/util/Random.main.lsl:383 - */ - public long nextLong() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = Engine.makeSymbolicLong(); - } - return result; - } - - /** - * [FUNCTION] RandomAutomaton::setSeed(Random, long) -> void - * Source: java/util/Random.main.lsl:389 - */ - public synchronized void setSeed(long seed) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - Engine.assume(true); - } - } - - /** - * [FUNCTION] RandomAutomaton::readObject(ObjectInputStream) -> void - * Source: java/util/Random.main.lsl:397 - */ - private void readObject(ObjectInputStream s) throws java.io.IOException, - java.lang.ClassNotFoundException { - /* body */ { - LibSLRuntime.not_implemented(/* no serialization support */); - } - } - - /** - * [FUNCTION] RandomAutomaton::writeObject(ObjectOutputStream) -> void - * Source: java/util/Random.main.lsl:403 - */ - private synchronized void writeObject(ObjectOutputStream s) throws java.io.IOException { - /* body */ { - LibSLRuntime.not_implemented(/* no serialization support */); - } - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(Random.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/RandomImpl.java b/approximations/src/main/java/generated/java/util/RandomImpl.java new file mode 100644 index 00000000..880252f6 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/RandomImpl.java @@ -0,0 +1,237 @@ +package generated.java.util; + +import generated.java.util.stream.DoubleStreamImpl; +import generated.java.util.stream.IntStreamImpl; +import generated.java.util.stream.LongStreamImpl; +import generated.runtime.LibSLGlobals; + +import java.io.*; +import java.lang.IllegalArgumentException; +import java.util.stream.DoubleStream; +import java.util.stream.IntStream; +import java.util.stream.LongStream; +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +@SuppressWarnings("unused") +@Approximate(java.util.Random.class) +public class RandomImpl implements Serializable { + + @Serial + private static final long serialVersionUID = 3905348978240129619L; + + @Serial + private static final ObjectStreamField[] serialPersistentFields = {}; + + static { + Engine.assume(true); + } + + public RandomImpl() { + Engine.assume(true); + } + + public RandomImpl(long seed) { + Engine.assume(true); + } + + private int[] _generateRandomIntegerArrayWithBounds(int size, int randomNumberOrigin, int randomNumberBound) { + int[] result = Engine.makeSymbolicIntArray(size); + for (int i = 0; i < size; i++) { + int item = result[i]; + Engine.assume(item >= randomNumberOrigin); + Engine.assume(item < randomNumberBound); + } + return result; + } + + private long[] _generateRandomLongArrayWithBounds(int size, long randomNumberOrigin, long randomNumberBound) { + long[] result = Engine.makeSymbolicLongArray(size); + for (int i = 0; i < size; i++) { + long item = result[i]; + Engine.assume(item >= randomNumberOrigin); + Engine.assume(item < randomNumberBound); + } + return result; + } + + private double[] _generateRandomDoubleArrayWithBounds(int size, double randomNumberOrigin, double randomNumberBound) { + double[] result = Engine.makeSymbolicDoubleArray(size); + for (int i = 0; i < size; i++) { + double item = result[i]; + Engine.assume(item >= randomNumberOrigin); + Engine.assume(item < randomNumberBound); + } + return result; + } + + public DoubleStream doubles() { + double[] items = _generateRandomDoubleArrayWithBounds(LibSLGlobals.RANDOM_STREAM_SIZE_MAX, 0, 1); + return new DoubleStreamImpl(items); + } + + public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound) { + if (randomNumberOrigin >= randomNumberBound) + throw new IllegalArgumentException(); + + double[] items = _generateRandomDoubleArrayWithBounds(LibSLGlobals.RANDOM_STREAM_SIZE_MAX, randomNumberOrigin, randomNumberBound); + return new DoubleStreamImpl(items); + } + + public DoubleStream doubles(long streamSize) { + int size = (int) streamSize; + if (size < 0) + throw new IllegalArgumentException(); + + if (size > LibSLGlobals.RANDOM_STREAM_SIZE_MAX) + size = LibSLGlobals.RANDOM_STREAM_SIZE_MAX; + return new DoubleStreamImpl(Engine.makeSymbolicDoubleArray(size)); + } + + public DoubleStream doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) { + int size = (int) streamSize; + if (size < 0) + throw new IllegalArgumentException(); + + if (randomNumberOrigin >= randomNumberBound) + throw new IllegalArgumentException(); + + if (size > LibSLGlobals.RANDOM_STREAM_SIZE_MAX) + size = LibSLGlobals.RANDOM_STREAM_SIZE_MAX; + + double[] items = _generateRandomDoubleArrayWithBounds(size, randomNumberOrigin, randomNumberBound); + return new DoubleStreamImpl(items); + } + + public IntStream ints() { + int[] items = Engine.makeSymbolicIntArray(LibSLGlobals.RANDOM_STREAM_SIZE_MAX); + return new IntStreamImpl(items); + } + + public IntStream ints(int randomNumberOrigin, int randomNumberBound) { + if (randomNumberOrigin >= randomNumberBound) + throw new IllegalArgumentException(); + + int[] items = _generateRandomIntegerArrayWithBounds(LibSLGlobals.RANDOM_STREAM_SIZE_MAX, randomNumberOrigin, randomNumberBound); + return new IntStreamImpl(items); + } + + public IntStream ints(long streamSize) { + int size = (int) streamSize; + if (size < 0) + throw new IllegalArgumentException(); + + if (size > LibSLGlobals.RANDOM_STREAM_SIZE_MAX) + size = LibSLGlobals.RANDOM_STREAM_SIZE_MAX; + + int[] items = Engine.makeSymbolicIntArray(size); + return new IntStreamImpl(items); + } + + public IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberBound) { + int size = ((int) streamSize); + if (size < 0) + throw new IllegalArgumentException(); + + if (randomNumberOrigin >= randomNumberBound) + throw new IllegalArgumentException(); + + if (size > LibSLGlobals.RANDOM_STREAM_SIZE_MAX) + size = LibSLGlobals.RANDOM_STREAM_SIZE_MAX; + + int[] items = _generateRandomIntegerArrayWithBounds(size, randomNumberOrigin, randomNumberBound); + return new IntStreamImpl(items); + } + + public LongStream longs() { + long[] items = Engine.makeSymbolicLongArray(LibSLGlobals.RANDOM_STREAM_SIZE_MAX); + return new LongStreamImpl(items); + } + + public LongStream longs(long streamSize) { + int size = (int) streamSize; + if (size < 0) + throw new IllegalArgumentException(); + + if (size > LibSLGlobals.RANDOM_STREAM_SIZE_MAX) + size = LibSLGlobals.RANDOM_STREAM_SIZE_MAX; + + return new LongStreamImpl(Engine.makeSymbolicLongArray(size)); + } + + public LongStream longs(long randomNumberOrigin, long randomNumberBound) { + if (randomNumberOrigin >= randomNumberBound) + throw new IllegalArgumentException(); + + long[] items = _generateRandomLongArrayWithBounds(LibSLGlobals.RANDOM_STREAM_SIZE_MAX, randomNumberOrigin, randomNumberBound); + return new LongStreamImpl(items); + } + + public LongStream longs(long streamSize, long randomNumberOrigin, long randomNumberBound) { + int size = (int) streamSize; + if (size < 0) + throw new IllegalArgumentException(); + + if (randomNumberOrigin >= randomNumberBound) + throw new IllegalArgumentException(); + + if (size > LibSLGlobals.RANDOM_STREAM_SIZE_MAX) + size = LibSLGlobals.RANDOM_STREAM_SIZE_MAX; + + return new LongStreamImpl(_generateRandomLongArrayWithBounds(size, randomNumberOrigin, randomNumberBound)); + } + + public boolean nextBoolean() { + return Engine.makeSymbolicBoolean(); + } + + public void nextBytes(byte[] bytes) { + int numBytes = bytes.length; + byte[] symbolicArray = Engine.makeSymbolicByteArray(numBytes); + LibSLRuntime.ArrayActions.copy(symbolicArray, 0, bytes, 0, numBytes); + } + + public double nextDouble() { + double result = Engine.makeSymbolicDouble(); + Engine.assume(0.0d <= result); + Engine.assume(result < 1.0d); + return result; + } + + public float nextFloat() { + float result = Engine.makeSymbolicFloat(); + Engine.assume(0.0f <= result); + Engine.assume(result < 1.0f); + return result; + } + + public synchronized double nextGaussian() { + double result = Engine.makeSymbolicDouble(); + boolean isNaN = result != result; + Engine.assume(!isNaN); + return result; + } + + public int nextInt() { + return Engine.makeSymbolicInt(); + } + + public int nextInt(int bound) { + if (bound <= 0) + throw new IllegalArgumentException("bound must be positive"); + + int result = Engine.makeSymbolicInt(); + Engine.assume(0 <= result); + Engine.assume(result < bound); + return result; + } + + public long nextLong() { + return Engine.makeSymbolicLong(); + } + + public synchronized void setSeed(long seed) { + Engine.assume(true); + } +} diff --git a/approximations/src/main/java/generated/java/util/ReadableImpl.java b/approximations/src/main/java/generated/java/util/ReadableImpl.java new file mode 100644 index 00000000..3202ee92 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/ReadableImpl.java @@ -0,0 +1,10 @@ +package generated.java.util; + +import org.jacodb.approximation.annotation.Approximate; + +import java.io.IOException; + +@Approximate(java.lang.Readable.class) +public interface ReadableImpl { + public int read(CharBufferImpl cb) throws IOException; +} diff --git a/approximations/src/main/java/generated/java/util/Spliterators.java b/approximations/src/main/java/generated/java/util/Spliterators.java deleted file mode 100644 index 355b29a9..00000000 --- a/approximations/src/main/java/generated/java/util/Spliterators.java +++ /dev/null @@ -1,204 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/Spliterators.lsl:18 -// - java/util/Spliterators.main.lsl:22 -// -package generated.java.util; - -import generated.runtime.LibSLGlobals; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Spliterator; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * SpliteratorsAutomaton for Spliterators ~> java.util.Spliterators - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.util.Spliterators.class) -public final class Spliterators implements LibSLRuntime.Automaton { - static { - Engine.assume(true); - } - - @LibSLRuntime.AutomatonConstructor - public Spliterators(Void __$lsl_token, final byte p0) { - } - - @LibSLRuntime.AutomatonConstructor - public Spliterators(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated); - } - - /** - * [CONSTRUCTOR] SpliteratorsAutomaton::(Spliterators) -> void - * Source: java/util/Spliterators.main.lsl:69 - */ - private Spliterators() { - this((Void) null); - /* body */ { - } - } - - /** - * [FUNCTION] SpliteratorsAutomaton::spliterator(array, int) -> Spliterator - * Source: java/util/Spliterators.main.lsl:147 - */ - public static Spliterator spliterator(Object[] arr, int additionalCharacteristics) { - Spliterator result = null; - /* body */ { - result = (stub.java.util.Spliterators_ArraySpliterator) ((Object) new Spliterators_ArraySpliterator((Void) null, - /* state = */ Spliterators_ArraySpliterator.__$lsl_States.Initialized, - /* array = */ arr, - /* index = */ 0, - /* fence = */ arr.length, - /* characteristics = */ additionalCharacteristics | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED - )); - } - return result; - } - - /** - * [FUNCTION] SpliteratorsAutomaton::spliterator(array, int, int, int) -> Spliterator - * Source: java/util/Spliterators.main.lsl:158 - */ - public static Spliterator spliterator(Object[] arr, int fromIndex, int toIndex, - int additionalCharacteristics) { - Spliterator result = null; - /* body */ { - result = (stub.java.util.Spliterators_ArraySpliterator) ((Object) new Spliterators_ArraySpliterator((Void) null, - /* state = */ Spliterators_ArraySpliterator.__$lsl_States.Initialized, - /* array = */ arr, - /* index = */ fromIndex, - /* fence = */ toIndex, - /* characteristics = */ additionalCharacteristics | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED - )); - } - return result; - } - - /** - * [FUNCTION] SpliteratorsAutomaton::spliterator(array, int) -> Spliterator_OfDouble - * Source: java/util/Spliterators.main.lsl:190 - */ - public static Spliterator.OfDouble spliterator(double[] arr, int additionalCharacteristics) { - Spliterator.OfDouble result = null; - /* body */ { - result = (stub.java.util.Spliterators_DoubleArraySpliterator) ((Object) new Spliterators_DoubleArraySpliterator((Void) null, - /* state = */ Spliterators_DoubleArraySpliterator.__$lsl_States.Initialized, - /* array = */ arr, - /* index = */ 0, - /* fence = */ arr.length, - /* characteristics = */ additionalCharacteristics | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED - )); - } - return result; - } - - /** - * [FUNCTION] SpliteratorsAutomaton::spliterator(array, int, int, int) -> Spliterator_OfDouble - * Source: java/util/Spliterators.main.lsl:201 - */ - public static Spliterator.OfDouble spliterator(double[] arr, int fromIndex, int toIndex, - int additionalCharacteristics) { - Spliterator.OfDouble result = null; - /* body */ { - result = (stub.java.util.Spliterators_DoubleArraySpliterator) ((Object) new Spliterators_DoubleArraySpliterator((Void) null, - /* state = */ Spliterators_DoubleArraySpliterator.__$lsl_States.Initialized, - /* array = */ arr, - /* index = */ fromIndex, - /* fence = */ toIndex, - /* characteristics = */ additionalCharacteristics | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED - )); - } - return result; - } - - /** - * [FUNCTION] SpliteratorsAutomaton::spliterator(array, int) -> Spliterator_OfInt - * Source: java/util/Spliterators.main.lsl:212 - */ - public static Spliterator.OfInt spliterator(int[] arr, int additionalCharacteristics) { - Spliterator.OfInt result = null; - /* body */ { - result = (stub.java.util.Spliterators_IntArraySpliterator) ((Object) new Spliterators_IntArraySpliterator((Void) null, - /* state = */ Spliterators_IntArraySpliterator.__$lsl_States.Initialized, - /* array = */ arr, - /* index = */ 0, - /* fence = */ arr.length, - /* characteristics = */ additionalCharacteristics | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED - )); - } - return result; - } - - /** - * [FUNCTION] SpliteratorsAutomaton::spliterator(array, int, int, int) -> Spliterator_OfInt - * Source: java/util/Spliterators.main.lsl:223 - */ - public static Spliterator.OfInt spliterator(int[] arr, int fromIndex, int toIndex, - int additionalCharacteristics) { - Spliterator.OfInt result = null; - /* body */ { - result = (stub.java.util.Spliterators_IntArraySpliterator) ((Object) new Spliterators_IntArraySpliterator((Void) null, - /* state = */ Spliterators_IntArraySpliterator.__$lsl_States.Initialized, - /* array = */ arr, - /* index = */ fromIndex, - /* fence = */ toIndex, - /* characteristics = */ additionalCharacteristics | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED - )); - } - return result; - } - - /** - * [FUNCTION] SpliteratorsAutomaton::spliterator(array, int) -> Spliterator_OfLong - * Source: java/util/Spliterators.main.lsl:234 - */ - public static Spliterator.OfLong spliterator(long[] arr, int additionalCharacteristics) { - Spliterator.OfLong result = null; - /* body */ { - result = (stub.java.util.Spliterators_LongArraySpliterator) ((Object) new Spliterators_LongArraySpliterator((Void) null, - /* state = */ Spliterators_LongArraySpliterator.__$lsl_States.Initialized, - /* array = */ arr, - /* index = */ 0, - /* fence = */ arr.length, - /* characteristics = */ additionalCharacteristics | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED - )); - } - return result; - } - - /** - * [FUNCTION] SpliteratorsAutomaton::spliterator(array, int, int, int) -> Spliterator_OfLong - * Source: java/util/Spliterators.main.lsl:245 - */ - public static Spliterator.OfLong spliterator(long[] arr, int fromIndex, int toIndex, - int additionalCharacteristics) { - Spliterator.OfLong result = null; - /* body */ { - result = (stub.java.util.Spliterators_LongArraySpliterator) ((Object) new Spliterators_LongArraySpliterator((Void) null, - /* state = */ Spliterators_LongArraySpliterator.__$lsl_States.Initialized, - /* array = */ arr, - /* index = */ fromIndex, - /* fence = */ toIndex, - /* characteristics = */ additionalCharacteristics | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED - )); - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - } - - @Approximate(Spliterators.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/SpliteratorsImpl.java b/approximations/src/main/java/generated/java/util/SpliteratorsImpl.java new file mode 100644 index 00000000..93745e95 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/SpliteratorsImpl.java @@ -0,0 +1,58 @@ +package generated.java.util; + +import generated.java.util.array.ArraySpliteratorImpl; +import generated.java.util.array.DoubleArraySpliteratorImpl; +import generated.java.util.array.IntArraySpliteratorImpl; +import generated.java.util.array.LongArraySpliteratorImpl; +import generated.runtime.LibSLGlobals; +import java.lang.Object; +import java.util.Spliterator; +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; + +@SuppressWarnings("unused") +@Approximate(java.util.Spliterators.class) +public final class SpliteratorsImpl { + + static { + Engine.assume(true); + } + + private SpliteratorsImpl() { } + + public static final int _characteristics = LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED; + + @SuppressWarnings("unchecked") + public static Spliterator spliterator(Object[] arr, int additionalCharacteristics) { + return new ArraySpliteratorImpl<>((T[]) arr, additionalCharacteristics); + } + + @SuppressWarnings("unchecked") + public static Spliterator spliterator(Object[] arr, int fromIndex, int toIndex, int additionalCharacteristics) { + return new ArraySpliteratorImpl<>((T[]) arr, fromIndex, toIndex, additionalCharacteristics); + } + + public static Spliterator.OfDouble spliterator(double[] arr, int additionalCharacteristics) { + return new DoubleArraySpliteratorImpl(arr, additionalCharacteristics); + } + + public static Spliterator.OfDouble spliterator(double[] arr, int fromIndex, int toIndex, int additionalCharacteristics) { + return new DoubleArraySpliteratorImpl(arr, fromIndex, toIndex, additionalCharacteristics); + } + + public static Spliterator.OfInt spliterator(int[] arr, int additionalCharacteristics) { + return new IntArraySpliteratorImpl(arr, additionalCharacteristics); + } + + public static Spliterator.OfInt spliterator(int[] arr, int fromIndex, int toIndex, int additionalCharacteristics) { + return new IntArraySpliteratorImpl(arr, fromIndex, toIndex, additionalCharacteristics); + } + + public static Spliterator.OfLong spliterator(long[] arr, int additionalCharacteristics) { + return new LongArraySpliteratorImpl(arr, additionalCharacteristics); + } + + public static Spliterator.OfLong spliterator(long[] arr, int fromIndex, int toIndex, int additionalCharacteristics) { + return new LongArraySpliteratorImpl(arr, fromIndex, toIndex, additionalCharacteristics); + } +} diff --git a/approximations/src/main/java/generated/java/util/Spliterators_ArraySpliterator.java b/approximations/src/main/java/generated/java/util/Spliterators_ArraySpliterator.java deleted file mode 100644 index 219cc8a5..00000000 --- a/approximations/src/main/java/generated/java/util/Spliterators_ArraySpliterator.java +++ /dev/null @@ -1,256 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/Spliterators.lsl:44 -// - java/util/Spliterators.ArraySpliterator.lsl:21 -// -package generated.java.util; - -import generated.runtime.LibSLGlobals; -import java.lang.IllegalStateException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Comparator; -import java.util.Spliterator; -import java.util.function.Consumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * Spliterators_ArraySpliteratorAutomaton for Spliterators_ArraySpliterator ~> java.util.Spliterators_ArraySpliterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.Spliterators_ArraySpliterator.class) -public final class Spliterators_ArraySpliterator implements LibSLRuntime.Automaton, Spliterator { - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public Object[] array; - - public int index; - - public int fence; - - public int characteristics; - - @LibSLRuntime.AutomatonConstructor - public Spliterators_ArraySpliterator(Void __$lsl_token, final byte p0, final Object[] p1, - final int p2, final int p3, final int p4) { - this.__$lsl_state = p0; - this.array = p1; - this.index = p2; - this.fence = p3; - this.characteristics = p4; - } - - @LibSLRuntime.AutomatonConstructor - public Spliterators_ArraySpliterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, null, 0, 0, 0); - } - - /** - * [CONSTRUCTOR] Spliterators_ArraySpliteratorAutomaton::(Spliterators_ArraySpliterator, array, int) -> void - * Source: java/util/Spliterators.ArraySpliterator.lsl:79 - */ - public Spliterators_ArraySpliterator(Object[] arr, int additionalCharacteristics) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.array = arr; - this.index = 0; - this.fence = arr.length; - this.characteristics = additionalCharacteristics | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED; - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] Spliterators_ArraySpliteratorAutomaton::(Spliterators_ArraySpliterator, array, int, int, int) -> void - * Source: java/util/Spliterators.ArraySpliterator.lsl:91 - */ - public Spliterators_ArraySpliterator(Object[] arr, int origin, int pFence, - int additionalCharacteristics) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.array = arr; - this.index = origin; - this.fence = pFence; - this.characteristics = additionalCharacteristics | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED; - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] Spliterators_ArraySpliteratorAutomaton::_hasCharacteristics(int) -> boolean - * Source: java/util/Spliterators.ArraySpliterator.lsl:71 - */ - private boolean _hasCharacteristics(int _characteristics) { - boolean result = false; - /* body */ { - result = (this.characteristics & _characteristics) == _characteristics; - } - return result; - } - - /** - * [FUNCTION] Spliterators_ArraySpliteratorAutomaton::characteristics(Spliterators_ArraySpliterator) -> int - * Source: java/util/Spliterators.ArraySpliterator.lsl:107 - */ - public int characteristics() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.characteristics; - } - return result; - } - - /** - * [FUNCTION] Spliterators_ArraySpliteratorAutomaton::estimateSize(Spliterators_ArraySpliterator) -> long - * Source: java/util/Spliterators.ArraySpliterator.lsl:113 - */ - public long estimateSize() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((long) (this.fence - this.index)); - } - return result; - } - - /** - * [FUNCTION] Spliterators_ArraySpliteratorAutomaton::forEachRemaining(Spliterators_ArraySpliterator, Consumer) -> void - * Source: java/util/Spliterators.ArraySpliterator.lsl:143 - */ - public void forEachRemaining(Consumer _action) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - final Object[] a = this.array; - int hi = this.fence; - int i = this.index; - this.index = hi; - for (i = i; i < hi; i += 1) { - final Object item = a[i]; - _action.accept(item); - } - ; - } - } - - /** - * [FUNCTION] Spliterators_ArraySpliteratorAutomaton::getComparator(Spliterators_ArraySpliterator) -> Comparator - * Source: java/util/Spliterators.ArraySpliterator.lsl:158 - */ - public Comparator getComparator() { - Comparator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_hasCharacteristics(LibSLGlobals.SPLITERATOR_SORTED)) { - result = null; - } else { - throw new IllegalStateException(); - } - } - return result; - } - - /** - * [FUNCTION] Spliterators_ArraySpliteratorAutomaton::getExactSizeIfKnown(Spliterators_ArraySpliterator) -> long - * Source: java/util/Spliterators.ArraySpliterator.lsl:167 - */ - public long getExactSizeIfKnown() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((long) (this.fence - this.index)); - } - return result; - } - - /** - * [FUNCTION] Spliterators_ArraySpliteratorAutomaton::hasCharacteristics(Spliterators_ArraySpliterator, int) -> boolean - * Source: java/util/Spliterators.ArraySpliterator.lsl:173 - */ - public boolean hasCharacteristics(int _characteristics) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _hasCharacteristics(_characteristics); - } - return result; - } - - /** - * [FUNCTION] Spliterators_ArraySpliteratorAutomaton::tryAdvance(Spliterators_ArraySpliterator, Consumer) -> boolean - * Source: java/util/Spliterators.ArraySpliterator.lsl:203 - */ - public boolean tryAdvance(Consumer _action) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - final int hi = this.fence; - final int i = this.index; - if (i < hi) { - this.index = i + 1; - final Object item = array[i]; - _action.accept(item); - result = true; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] Spliterators_ArraySpliteratorAutomaton::trySplit(Spliterators_ArraySpliterator) -> Spliterator - * Source: java/util/Spliterators.ArraySpliterator.lsl:218 - */ - public Spliterator trySplit() { - Spliterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int hi = this.fence; - final int lo = this.index; - final int mid = (lo + hi) >>> 1; - if (lo >= mid) { - result = null; - } else { - result = (stub.java.util.Spliterators_ArraySpliterator) ((Object) new Spliterators_ArraySpliterator((Void) null, - /* state = */ Spliterators_ArraySpliterator.__$lsl_States.Initialized, - /* array = */ this.array, - /* index = */ lo, - /* fence = */ mid, - /* characteristics = */ this.characteristics - )); - } - this.index = mid; - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(Spliterators_ArraySpliterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/Spliterators_DoubleArraySpliterator.java b/approximations/src/main/java/generated/java/util/Spliterators_DoubleArraySpliterator.java deleted file mode 100644 index 599f5e59..00000000 --- a/approximations/src/main/java/generated/java/util/Spliterators_DoubleArraySpliterator.java +++ /dev/null @@ -1,304 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/Spliterators.lsl:53 -// - java/util/Spliterators.DoubleArraySpliterator.lsl:21 -// -package generated.java.util; - -import generated.runtime.LibSLGlobals; -import java.lang.IllegalStateException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Comparator; -import java.util.Spliterator; -import java.util.function.Consumer; -import java.util.function.DoubleConsumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * Spliterators_DoubleArraySpliteratorAutomaton for Spliterators_DoubleArraySpliterator ~> java.util.Spliterators_DoubleArraySpliterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.Spliterators_DoubleArraySpliterator.class) -public final class Spliterators_DoubleArraySpliterator implements LibSLRuntime.Automaton, Spliterator.OfDouble { - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public double[] array; - - public int index; - - public int fence; - - public int characteristics; - - @LibSLRuntime.AutomatonConstructor - public Spliterators_DoubleArraySpliterator(Void __$lsl_token, final byte p0, final double[] p1, - final int p2, final int p3, final int p4) { - this.__$lsl_state = p0; - this.array = p1; - this.index = p2; - this.fence = p3; - this.characteristics = p4; - } - - @LibSLRuntime.AutomatonConstructor - public Spliterators_DoubleArraySpliterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, null, 0, 0, 0); - } - - /** - * [CONSTRUCTOR] Spliterators_DoubleArraySpliteratorAutomaton::(Spliterators_DoubleArraySpliterator, array, int) -> void - * Source: java/util/Spliterators.DoubleArraySpliterator.lsl:81 - */ - public Spliterators_DoubleArraySpliterator(double[] arr, int additionalCharacteristics) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.array = arr; - this.index = 0; - this.fence = arr.length; - this.characteristics = additionalCharacteristics | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED; - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] Spliterators_DoubleArraySpliteratorAutomaton::(Spliterators_DoubleArraySpliterator, array, int, int, int) -> void - * Source: java/util/Spliterators.DoubleArraySpliterator.lsl:93 - */ - public Spliterators_DoubleArraySpliterator(double[] arr, int origin, int pFence, - int additionalCharacteristics) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.array = arr; - this.index = origin; - this.fence = pFence; - this.characteristics = additionalCharacteristics | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED; - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] Spliterators_DoubleArraySpliteratorAutomaton::_hasCharacteristics(int) -> boolean - * Source: java/util/Spliterators.DoubleArraySpliterator.lsl:73 - */ - private boolean _hasCharacteristics(int _characteristics) { - boolean result = false; - /* body */ { - result = (this.characteristics & _characteristics) == _characteristics; - } - return result; - } - - /** - * [FUNCTION] Spliterators_DoubleArraySpliteratorAutomaton::characteristics(Spliterators_DoubleArraySpliterator) -> int - * Source: java/util/Spliterators.DoubleArraySpliterator.lsl:109 - */ - public int characteristics() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.characteristics; - } - return result; - } - - /** - * [FUNCTION] Spliterators_DoubleArraySpliteratorAutomaton::estimateSize(Spliterators_DoubleArraySpliterator) -> long - * Source: java/util/Spliterators.DoubleArraySpliterator.lsl:115 - */ - public long estimateSize() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((long) (this.fence - this.index)); - } - return result; - } - - /** - * [FUNCTION] Spliterators_DoubleArraySpliteratorAutomaton::forEachRemaining(Spliterators_DoubleArraySpliterator, DoubleConsumer) -> void - * Source: java/util/Spliterators.DoubleArraySpliterator.lsl:145 - */ - public void forEachRemaining(DoubleConsumer _action) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - final double[] a = this.array; - int hi = this.fence; - int i = this.index; - this.index = hi; - for (i = i; i < hi; i += 1) { - final double item = a[i]; - _action.accept(item); - } - ; - } - } - - /** - * [FUNCTION] Spliterators_DoubleArraySpliteratorAutomaton::forEachRemaining(Spliterators_DoubleArraySpliterator, Consumer) -> void - * Source: java/util/Spliterators.DoubleArraySpliterator.lsl:151 - */ - public void forEachRemaining(Consumer _action) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - final double[] a = this.array; - int hi = this.fence; - int i = this.index; - this.index = hi; - for (i = i; i < hi; i += 1) { - final double item = a[i]; - _action.accept(item); - } - ; - } - } - - /** - * [FUNCTION] Spliterators_DoubleArraySpliteratorAutomaton::getComparator(Spliterators_DoubleArraySpliterator) -> Comparator - * Source: java/util/Spliterators.DoubleArraySpliterator.lsl:166 - */ - public Comparator getComparator() { - Comparator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_hasCharacteristics(LibSLGlobals.SPLITERATOR_SORTED)) { - result = null; - } else { - throw new IllegalStateException(); - } - } - return result; - } - - /** - * [FUNCTION] Spliterators_DoubleArraySpliteratorAutomaton::getExactSizeIfKnown(Spliterators_DoubleArraySpliterator) -> long - * Source: java/util/Spliterators.DoubleArraySpliterator.lsl:175 - */ - public long getExactSizeIfKnown() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((long) (this.fence - this.index)); - } - return result; - } - - /** - * [FUNCTION] Spliterators_DoubleArraySpliteratorAutomaton::hasCharacteristics(Spliterators_DoubleArraySpliterator, int) -> boolean - * Source: java/util/Spliterators.DoubleArraySpliterator.lsl:181 - */ - public boolean hasCharacteristics(int _characteristics) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _hasCharacteristics(_characteristics); - } - return result; - } - - /** - * [FUNCTION] Spliterators_DoubleArraySpliteratorAutomaton::tryAdvance(Spliterators_DoubleArraySpliterator, DoubleConsumer) -> boolean - * Source: java/util/Spliterators.DoubleArraySpliterator.lsl:211 - */ - public boolean tryAdvance(DoubleConsumer _action) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - final int hi = this.fence; - final int i = this.index; - if (i < hi) { - this.index = i + 1; - final double item = array[i]; - _action.accept(item); - result = true; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] Spliterators_DoubleArraySpliteratorAutomaton::tryAdvance(Spliterators_DoubleArraySpliterator, Consumer) -> boolean - * Source: java/util/Spliterators.DoubleArraySpliterator.lsl:217 - */ - public boolean tryAdvance(Consumer _action) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - final int hi = this.fence; - final int i = this.index; - if (i < hi) { - this.index = i + 1; - final double item = array[i]; - _action.accept(item); - result = true; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] Spliterators_DoubleArraySpliteratorAutomaton::trySplit(Spliterators_DoubleArraySpliterator) -> Spliterator_OfDouble - * Source: java/util/Spliterators.DoubleArraySpliterator.lsl:232 - */ - public Spliterator.OfDouble trySplit() { - Spliterator.OfDouble result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int hi = this.fence; - final int lo = this.index; - final int mid = (lo + hi) >>> 1; - if (lo >= mid) { - result = null; - } else { - result = (stub.java.util.Spliterators_DoubleArraySpliterator) ((Object) new Spliterators_DoubleArraySpliterator((Void) null, - /* state = */ Spliterators_DoubleArraySpliterator.__$lsl_States.Initialized, - /* array = */ this.array, - /* index = */ lo, - /* fence = */ mid, - /* characteristics = */ this.characteristics - )); - } - this.index = mid; - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(Spliterators_DoubleArraySpliterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/Spliterators_IntArraySpliterator.java b/approximations/src/main/java/generated/java/util/Spliterators_IntArraySpliterator.java deleted file mode 100644 index c0d80fc7..00000000 --- a/approximations/src/main/java/generated/java/util/Spliterators_IntArraySpliterator.java +++ /dev/null @@ -1,304 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/Spliterators.lsl:62 -// - java/util/Spliterators.IntArraySpliterator.lsl:21 -// -package generated.java.util; - -import generated.runtime.LibSLGlobals; -import java.lang.IllegalStateException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Comparator; -import java.util.Spliterator; -import java.util.function.Consumer; -import java.util.function.IntConsumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * Spliterators_IntArraySpliteratorAutomaton for Spliterators_IntArraySpliterator ~> java.util.Spliterators_IntArraySpliterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.Spliterators_IntArraySpliterator.class) -public final class Spliterators_IntArraySpliterator implements LibSLRuntime.Automaton, Spliterator.OfInt { - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public int[] array; - - public int index; - - public int fence; - - public int characteristics; - - @LibSLRuntime.AutomatonConstructor - public Spliterators_IntArraySpliterator(Void __$lsl_token, final byte p0, final int[] p1, - final int p2, final int p3, final int p4) { - this.__$lsl_state = p0; - this.array = p1; - this.index = p2; - this.fence = p3; - this.characteristics = p4; - } - - @LibSLRuntime.AutomatonConstructor - public Spliterators_IntArraySpliterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, null, 0, 0, 0); - } - - /** - * [CONSTRUCTOR] Spliterators_IntArraySpliteratorAutomaton::(Spliterators_IntArraySpliterator, array, int) -> void - * Source: java/util/Spliterators.IntArraySpliterator.lsl:81 - */ - public Spliterators_IntArraySpliterator(int[] arr, int additionalCharacteristics) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.array = arr; - this.index = 0; - this.fence = arr.length; - this.characteristics = additionalCharacteristics | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED; - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] Spliterators_IntArraySpliteratorAutomaton::(Spliterators_IntArraySpliterator, array, int, int, int) -> void - * Source: java/util/Spliterators.IntArraySpliterator.lsl:93 - */ - public Spliterators_IntArraySpliterator(int[] arr, int origin, int pFence, - int additionalCharacteristics) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.array = arr; - this.index = origin; - this.fence = pFence; - this.characteristics = additionalCharacteristics | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED; - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] Spliterators_IntArraySpliteratorAutomaton::_hasCharacteristics(int) -> boolean - * Source: java/util/Spliterators.IntArraySpliterator.lsl:73 - */ - private boolean _hasCharacteristics(int _characteristics) { - boolean result = false; - /* body */ { - result = (this.characteristics & _characteristics) == _characteristics; - } - return result; - } - - /** - * [FUNCTION] Spliterators_IntArraySpliteratorAutomaton::characteristics(Spliterators_IntArraySpliterator) -> int - * Source: java/util/Spliterators.IntArraySpliterator.lsl:109 - */ - public int characteristics() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.characteristics; - } - return result; - } - - /** - * [FUNCTION] Spliterators_IntArraySpliteratorAutomaton::estimateSize(Spliterators_IntArraySpliterator) -> long - * Source: java/util/Spliterators.IntArraySpliterator.lsl:115 - */ - public long estimateSize() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((long) (this.fence - this.index)); - } - return result; - } - - /** - * [FUNCTION] Spliterators_IntArraySpliteratorAutomaton::forEachRemaining(Spliterators_IntArraySpliterator, Consumer) -> void - * Source: java/util/Spliterators.IntArraySpliterator.lsl:145 - */ - public void forEachRemaining(Consumer _action) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - final int[] a = this.array; - int hi = this.fence; - int i = this.index; - this.index = hi; - for (i = i; i < hi; i += 1) { - final int item = a[i]; - _action.accept(item); - } - ; - } - } - - /** - * [FUNCTION] Spliterators_IntArraySpliteratorAutomaton::forEachRemaining(Spliterators_IntArraySpliterator, IntConsumer) -> void - * Source: java/util/Spliterators.IntArraySpliterator.lsl:151 - */ - public void forEachRemaining(IntConsumer _action) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - final int[] a = this.array; - int hi = this.fence; - int i = this.index; - this.index = hi; - for (i = i; i < hi; i += 1) { - final int item = a[i]; - _action.accept(item); - } - ; - } - } - - /** - * [FUNCTION] Spliterators_IntArraySpliteratorAutomaton::getComparator(Spliterators_IntArraySpliterator) -> Comparator - * Source: java/util/Spliterators.IntArraySpliterator.lsl:166 - */ - public Comparator getComparator() { - Comparator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_hasCharacteristics(LibSLGlobals.SPLITERATOR_SORTED)) { - result = null; - } else { - throw new IllegalStateException(); - } - } - return result; - } - - /** - * [FUNCTION] Spliterators_IntArraySpliteratorAutomaton::getExactSizeIfKnown(Spliterators_IntArraySpliterator) -> long - * Source: java/util/Spliterators.IntArraySpliterator.lsl:175 - */ - public long getExactSizeIfKnown() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((long) (this.fence - this.index)); - } - return result; - } - - /** - * [FUNCTION] Spliterators_IntArraySpliteratorAutomaton::hasCharacteristics(Spliterators_IntArraySpliterator, int) -> boolean - * Source: java/util/Spliterators.IntArraySpliterator.lsl:181 - */ - public boolean hasCharacteristics(int _characteristics) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _hasCharacteristics(_characteristics); - } - return result; - } - - /** - * [FUNCTION] Spliterators_IntArraySpliteratorAutomaton::tryAdvance(Spliterators_IntArraySpliterator, IntConsumer) -> boolean - * Source: java/util/Spliterators.IntArraySpliterator.lsl:211 - */ - public boolean tryAdvance(IntConsumer _action) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - final int hi = this.fence; - final int i = this.index; - if (i < hi) { - this.index = i + 1; - final int item = array[i]; - _action.accept(item); - result = true; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] Spliterators_IntArraySpliteratorAutomaton::tryAdvance(Spliterators_IntArraySpliterator, Consumer) -> boolean - * Source: java/util/Spliterators.IntArraySpliterator.lsl:217 - */ - public boolean tryAdvance(Consumer _action) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - final int hi = this.fence; - final int i = this.index; - if (i < hi) { - this.index = i + 1; - final int item = array[i]; - _action.accept(item); - result = true; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] Spliterators_IntArraySpliteratorAutomaton::trySplit(Spliterators_IntArraySpliterator) -> Spliterator_OfInt - * Source: java/util/Spliterators.IntArraySpliterator.lsl:232 - */ - public Spliterator.OfInt trySplit() { - Spliterator.OfInt result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int hi = this.fence; - final int lo = this.index; - final int mid = (lo + hi) >>> 1; - if (lo >= mid) { - result = null; - } else { - result = (stub.java.util.Spliterators_IntArraySpliterator) ((Object) new Spliterators_IntArraySpliterator((Void) null, - /* state = */ Spliterators_IntArraySpliterator.__$lsl_States.Initialized, - /* array = */ this.array, - /* index = */ lo, - /* fence = */ mid, - /* characteristics = */ this.characteristics - )); - } - this.index = mid; - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(Spliterators_IntArraySpliterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/Spliterators_LongArraySpliterator.java b/approximations/src/main/java/generated/java/util/Spliterators_LongArraySpliterator.java deleted file mode 100644 index 0c3ab260..00000000 --- a/approximations/src/main/java/generated/java/util/Spliterators_LongArraySpliterator.java +++ /dev/null @@ -1,304 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/Spliterators.lsl:71 -// - java/util/Spliterators.LongArraySpliterator.lsl:21 -// -package generated.java.util; - -import generated.runtime.LibSLGlobals; -import java.lang.IllegalStateException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Comparator; -import java.util.Spliterator; -import java.util.function.Consumer; -import java.util.function.LongConsumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * Spliterators_LongArraySpliteratorAutomaton for Spliterators_LongArraySpliterator ~> java.util.Spliterators_LongArraySpliterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.Spliterators_LongArraySpliterator.class) -public final class Spliterators_LongArraySpliterator implements LibSLRuntime.Automaton, Spliterator.OfLong { - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public long[] array; - - public int index; - - public int fence; - - public int characteristics; - - @LibSLRuntime.AutomatonConstructor - public Spliterators_LongArraySpliterator(Void __$lsl_token, final byte p0, final long[] p1, - final int p2, final int p3, final int p4) { - this.__$lsl_state = p0; - this.array = p1; - this.index = p2; - this.fence = p3; - this.characteristics = p4; - } - - @LibSLRuntime.AutomatonConstructor - public Spliterators_LongArraySpliterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, null, 0, 0, 0); - } - - /** - * [CONSTRUCTOR] Spliterators_LongArraySpliteratorAutomaton::(Spliterators_LongArraySpliterator, array, int) -> void - * Source: java/util/Spliterators.LongArraySpliterator.lsl:81 - */ - public Spliterators_LongArraySpliterator(long[] arr, int additionalCharacteristics) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.array = arr; - this.index = 0; - this.fence = arr.length; - this.characteristics = additionalCharacteristics | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED; - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] Spliterators_LongArraySpliteratorAutomaton::(Spliterators_LongArraySpliterator, array, int, int, int) -> void - * Source: java/util/Spliterators.LongArraySpliterator.lsl:93 - */ - public Spliterators_LongArraySpliterator(long[] arr, int origin, int pFence, - int additionalCharacteristics) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.array = arr; - this.index = origin; - this.fence = pFence; - this.characteristics = additionalCharacteristics | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED; - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [SUBROUTINE] Spliterators_LongArraySpliteratorAutomaton::_hasCharacteristics(int) -> boolean - * Source: java/util/Spliterators.LongArraySpliterator.lsl:73 - */ - private boolean _hasCharacteristics(int _characteristics) { - boolean result = false; - /* body */ { - result = (this.characteristics & _characteristics) == _characteristics; - } - return result; - } - - /** - * [FUNCTION] Spliterators_LongArraySpliteratorAutomaton::characteristics(Spliterators_LongArraySpliterator) -> int - * Source: java/util/Spliterators.LongArraySpliterator.lsl:109 - */ - public int characteristics() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.characteristics; - } - return result; - } - - /** - * [FUNCTION] Spliterators_LongArraySpliteratorAutomaton::estimateSize(Spliterators_LongArraySpliterator) -> long - * Source: java/util/Spliterators.LongArraySpliterator.lsl:115 - */ - public long estimateSize() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((long) (this.fence - this.index)); - } - return result; - } - - /** - * [FUNCTION] Spliterators_LongArraySpliteratorAutomaton::forEachRemaining(Spliterators_LongArraySpliterator, Consumer) -> void - * Source: java/util/Spliterators.LongArraySpliterator.lsl:145 - */ - public void forEachRemaining(Consumer _action) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - final long[] a = this.array; - int hi = this.fence; - int i = this.index; - this.index = hi; - for (i = i; i < hi; i += 1) { - final long item = a[i]; - _action.accept(item); - } - ; - } - } - - /** - * [FUNCTION] Spliterators_LongArraySpliteratorAutomaton::forEachRemaining(Spliterators_LongArraySpliterator, LongConsumer) -> void - * Source: java/util/Spliterators.LongArraySpliterator.lsl:151 - */ - public void forEachRemaining(LongConsumer _action) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - final long[] a = this.array; - int hi = this.fence; - int i = this.index; - this.index = hi; - for (i = i; i < hi; i += 1) { - final long item = a[i]; - _action.accept(item); - } - ; - } - } - - /** - * [FUNCTION] Spliterators_LongArraySpliteratorAutomaton::getComparator(Spliterators_LongArraySpliterator) -> Comparator - * Source: java/util/Spliterators.LongArraySpliterator.lsl:166 - */ - public Comparator getComparator() { - Comparator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_hasCharacteristics(LibSLGlobals.SPLITERATOR_SORTED)) { - result = null; - } else { - throw new IllegalStateException(); - } - } - return result; - } - - /** - * [FUNCTION] Spliterators_LongArraySpliteratorAutomaton::getExactSizeIfKnown(Spliterators_LongArraySpliterator) -> long - * Source: java/util/Spliterators.LongArraySpliterator.lsl:175 - */ - public long getExactSizeIfKnown() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((long) (this.fence - this.index)); - } - return result; - } - - /** - * [FUNCTION] Spliterators_LongArraySpliteratorAutomaton::hasCharacteristics(Spliterators_LongArraySpliterator, int) -> boolean - * Source: java/util/Spliterators.LongArraySpliterator.lsl:181 - */ - public boolean hasCharacteristics(int _characteristics) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = _hasCharacteristics(_characteristics); - } - return result; - } - - /** - * [FUNCTION] Spliterators_LongArraySpliteratorAutomaton::tryAdvance(Spliterators_LongArraySpliterator, LongConsumer) -> boolean - * Source: java/util/Spliterators.LongArraySpliterator.lsl:211 - */ - public boolean tryAdvance(LongConsumer _action) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - final int hi = this.fence; - final int i = this.index; - if (i < hi) { - this.index = i + 1; - final long item = array[i]; - _action.accept(item); - result = true; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] Spliterators_LongArraySpliteratorAutomaton::tryAdvance(Spliterators_LongArraySpliterator, Consumer) -> boolean - * Source: java/util/Spliterators.LongArraySpliterator.lsl:217 - */ - public boolean tryAdvance(Consumer _action) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - final int hi = this.fence; - final int i = this.index; - if (i < hi) { - this.index = i + 1; - final long item = array[i]; - _action.accept(item); - result = true; - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] Spliterators_LongArraySpliteratorAutomaton::trySplit(Spliterators_LongArraySpliterator) -> Spliterator_OfLong - * Source: java/util/Spliterators.LongArraySpliterator.lsl:232 - */ - public Spliterator.OfLong trySplit() { - Spliterator.OfLong result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int hi = this.fence; - final int lo = this.index; - final int mid = (lo + hi) >>> 1; - if (lo >= mid) { - result = null; - } else { - result = (stub.java.util.Spliterators_LongArraySpliterator) ((Object) new Spliterators_LongArraySpliterator((Void) null, - /* state = */ Spliterators_LongArraySpliterator.__$lsl_States.Initialized, - /* array = */ this.array, - /* index = */ lo, - /* fence = */ mid, - /* characteristics = */ this.characteristics - )); - } - this.index = mid; - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(Spliterators_LongArraySpliterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/array/AbstractArrayIteratorImpl.java b/approximations/src/main/java/generated/java/util/array/AbstractArrayIteratorImpl.java new file mode 100644 index 00000000..3241cae4 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/array/AbstractArrayIteratorImpl.java @@ -0,0 +1,60 @@ +package generated.java.util.array; + +import generated.java.util.AbstractIteratorImpl; +import org.jacodb.approximation.annotation.Approximate; +import stub.java.util.array.AbstractArrayIterator; + +import java.util.NoSuchElementException; +import java.util.function.Consumer; + +@Approximate(AbstractArrayIterator.class) +public abstract class AbstractArrayIteratorImpl extends AbstractIteratorImpl { + + public int cursor; + + AbstractArrayIteratorImpl(int cursor) { + super(0); + this.cursor = cursor; + } + + protected final int _parentModCount() { + return 0; + } + + abstract protected int _getLength(); + + abstract protected E _getItem(int index); + + protected boolean _isEmpty() { + return this.cursor >= _getLength(); + } + + public boolean hasNext() { + return !_isEmpty(); + } + + public E next() { + if (this.cursor >= _getLength()) + throw new NoSuchElementException(); + + return _getItem(this.cursor++); + } + + public void remove() { + throw new UnsupportedOperationException(); + } + + public void forEachRemaining(Consumer userAction) { + if (userAction == null) + throw new NullPointerException(); + + int length = _getLength(); + if (this.cursor >= length) + return; + + while (this.cursor < length) { + E item = _getItem(this.cursor++); + userAction.accept(item); + } + } +} diff --git a/approximations/src/main/java/generated/java/util/array/AbstractArraySpliteratorImpl.java b/approximations/src/main/java/generated/java/util/array/AbstractArraySpliteratorImpl.java new file mode 100644 index 00000000..e1069e55 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/array/AbstractArraySpliteratorImpl.java @@ -0,0 +1,91 @@ +package generated.java.util.array; + +import generated.java.util.AbstractSpliteratorImpl; +import generated.java.util.SpliteratorsImpl; +import generated.runtime.LibSLGlobals; +import org.jacodb.approximation.annotation.Approximate; +import stub.java.util.array.AbstractArraySpliterator; + +import java.util.Comparator; +import java.util.function.Consumer; + +@Approximate(AbstractArraySpliterator.class) +public abstract class AbstractArraySpliteratorImpl extends AbstractSpliteratorImpl { + + public int characteristics; + + public AbstractArraySpliteratorImpl(int index, int fence, int characteristics) { + super(index, fence, 0); + this.characteristics = characteristics | SpliteratorsImpl._characteristics; + } + + protected int _parentModCount() { + return 0; + } + + protected int _storageSize() { + return this.fence; + } + + protected int _getFence() { + return this.fence; + } + + protected void _checkForModification() { + } + + public boolean hasCharacteristics(int _characteristics) { + return (this.characteristics & _characteristics) == _characteristics; + } + + public int characteristics() { + return this.characteristics; + } + + public long estimateSize() { + return super.estimateSize(); + } + + abstract protected E _getItem(int index); + + public void forEachRemaining(Consumer _action) { + if (_action == null) + throw new NullPointerException(); + + int current = this.index; + this.index = this.fence; + for (int i = current; i < this.fence; i++) { + E item = _getItem(i); + _action.accept(item); + } + } + + public Comparator getComparator() { + if (hasCharacteristics(LibSLGlobals.SPLITERATOR_SORTED)) + return null; + + throw new IllegalStateException(); + } + + public long getExactSizeIfKnown() { + return super.getExactSizeIfKnown(); + } + + public boolean tryAdvance(Consumer _action) { + if (_action == null) + throw new NullPointerException(); + + int current = this.index; + if (current >= this.fence) + return false; + + this.index = current + 1; + E item = _getItem(current); + _action.accept(item); + return true; + } + + public AbstractArraySpliteratorImpl trySplit() { + return (AbstractArraySpliteratorImpl) super.trySplit(); + } +} diff --git a/approximations/src/main/java/generated/java/util/array/ArrayIteratorImpl.java b/approximations/src/main/java/generated/java/util/array/ArrayIteratorImpl.java new file mode 100644 index 00000000..25e400ca --- /dev/null +++ b/approximations/src/main/java/generated/java/util/array/ArrayIteratorImpl.java @@ -0,0 +1,54 @@ +package generated.java.util.array; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import stub.java.util.array.ArrayIterator; + +import java.util.function.Consumer; + +@Approximate(ArrayIterator.class) +public class ArrayIteratorImpl extends AbstractArrayIteratorImpl { + + private final E[] storage; + + public ArrayIteratorImpl(E[] storage, int cursor) { + super(cursor); + this.storage = storage; + } + + public ArrayIteratorImpl(E[] storage) { + this(storage, 0); + } + + @SuppressWarnings({"DataFlowIssue", "ConstantValue"}) + private E[] _getStorage() { + E[] storage = this.storage; + Engine.assume(storage != null); + Engine.assume(storage.length >= 0); + return storage; + } + + protected int _getLength() { + return _getStorage().length; + } + + protected E _getItem(int index) { + return _getStorage()[index]; + } + + public boolean hasNext() { + return super.hasNext(); + } + + public E next() { + return super.next(); + } + + public void remove() { + super.remove(); + } + + public void forEachRemaining(Consumer userAction) { + super.forEachRemaining(userAction); + } +} diff --git a/approximations/src/main/java/generated/java/util/array/ArraySpliteratorImpl.java b/approximations/src/main/java/generated/java/util/array/ArraySpliteratorImpl.java new file mode 100644 index 00000000..b6973f42 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/array/ArraySpliteratorImpl.java @@ -0,0 +1,67 @@ +package generated.java.util.array; + +import java.util.Comparator; +import java.util.function.Consumer; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import stub.java.util.array.ArraySpliterator; + +@Approximate(ArraySpliterator.class) +public final class ArraySpliteratorImpl extends AbstractArraySpliteratorImpl { + + public E[] array; + + public ArraySpliteratorImpl(E[] array, int index, int fence, int characteristics) { + super(index, fence, characteristics); + Engine.assume(array != null); + this.array = array; + } + + @SuppressWarnings("unused") + public ArraySpliteratorImpl(E[] arr, int additionalCharacteristics) { + this(arr, 0, arr.length, additionalCharacteristics); + } + + protected ArraySpliteratorImpl _create(int index, int fence) { + return new ArraySpliteratorImpl<>(this.array, index, fence, this.characteristics); + } + + @SuppressWarnings("DataFlowIssue") + protected E _getItem(int index) { + Engine.assume(array != null); + return array[index]; + } + + public int characteristics() { + return super.characteristics(); + } + + public long estimateSize() { + return super.estimateSize(); + } + + public void forEachRemaining(Consumer action) { + super.forEachRemaining(action); + } + + public Comparator getComparator() { + return super.getComparator(); + } + + public long getExactSizeIfKnown() { + return super.getExactSizeIfKnown(); + } + + public boolean hasCharacteristics(int characteristics) { + return super.hasCharacteristics(characteristics); + } + + public boolean tryAdvance(Consumer action) { + return super.tryAdvance(action); + } + + public ArraySpliteratorImpl trySplit() { + return (ArraySpliteratorImpl) super.trySplit(); + } +} diff --git a/approximations/src/main/java/generated/java/util/array/ArraysImpl.java b/approximations/src/main/java/generated/java/util/array/ArraysImpl.java new file mode 100644 index 00000000..ede67300 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/array/ArraysImpl.java @@ -0,0 +1,420 @@ +package generated.java.util.array; + +import org.jacodb.approximation.annotation.Approximate; + +import java.util.Comparator; + +@SuppressWarnings("unused") +@Approximate(java.util.Arrays.class) +public class ArraysImpl { + + private static void _checkArrayNull(Object array) { + if (array == null) + throw new NullPointerException(); + } + + private static void _rangeCheck(int arrayLength, int fromIndex, int toIndex) { + if (fromIndex > toIndex) + throw new IllegalArgumentException(); + + if (fromIndex < 0) + throw new ArrayIndexOutOfBoundsException(); + + if (toIndex > arrayLength) + throw new ArrayIndexOutOfBoundsException(); + } + + private static boolean _isEmpty(int arrayLength, int fromIndex, int toIndex) { + return toIndex - fromIndex == 0 || arrayLength == 0; + } + + private static void _sortIntArray(int[] array, int fromIndex, int toIndex) { + if (_isEmpty(array.length, fromIndex, toIndex)) + return; + + int outerLimit = toIndex - 1; + for (int i = 0; i < outerLimit; i++) { + int innerLimit = toIndex - i - 1; + for (int j = 0; j < innerLimit; j++) { + int idxB = j + 1; + int a = array[j]; + int b = array[idxB]; + if (a > b) { + array[j] = b; + array[idxB] = a; + } + } + } + } + + private static void _sortLongArray(long[] array, int fromIndex, int toIndex) { + if (_isEmpty(array.length, fromIndex, toIndex)) + return; + + int outerLimit = toIndex - 1; + for (int i = 0; i < outerLimit; i++) { + int innerLimit = toIndex - i - 1; + for (int j = 0; j < innerLimit; j++) { + int idxB = j + 1; + long a = array[j]; + long b = array[idxB]; + if (a > b) { + array[j] = b; + array[idxB] = a; + } + } + } + } + + private static void _sortShortArray(short[] array, int fromIndex, int toIndex) { + if (_isEmpty(array.length, fromIndex, toIndex)) + return; + + int outerLimit = toIndex - 1; + for (int i = 0; i < outerLimit; i++) { + int innerLimit = toIndex - i - 1; + for (int j = 0; j < innerLimit; j++) { + int idxB = j + 1; + short a = array[j]; + short b = array[idxB]; + if (a > b) { + array[j] = b; + array[idxB] = a; + } + } + } + } + + private static void _sortCharArray(char[] array, int fromIndex, int toIndex) { + if (_isEmpty(array.length, fromIndex, toIndex)) + return; + + int outerLimit = toIndex - 1; + for (int i = 0; i < outerLimit; i++) { + int innerLimit = toIndex - i - 1; + for (int j = 0; j < innerLimit; j++) { + int idxB = j + 1; + char a = array[j]; + char b = array[idxB]; + if (a > b) { + array[j] = b; + array[idxB] = a; + } + } + } + } + + private static void _sortByteArray(byte[] array, int fromIndex, int toIndex) { + if (_isEmpty(array.length, fromIndex, toIndex)) + return; + + int outerLimit = toIndex - 1; + for (int i = 0; i < outerLimit; i++) { + int innerLimit = toIndex - i - 1; + for (int j = 0; j < innerLimit; j++) { + int idxB = j + 1; + byte a = array[j]; + byte b = array[idxB]; + if (a > b) { + array[j] = b; + array[idxB] = a; + } + } + } + } + + private static void _sortFloatArray(float[] array, int fromIndex, int toIndex) { + if (_isEmpty(array.length, fromIndex, toIndex)) + return; + + int outerLimit = toIndex - 1; + for (int i = 0; i < outerLimit; i++) { + int innerLimit = toIndex - i - 1; + for (int j = 0; j < innerLimit; j++) { + int idxB = j + 1; + float a = array[j]; + float b = array[idxB]; + if (a > b) { + array[j] = b; + array[idxB] = a; + } + } + } + } + + private static void _sortDoubleArray(double[] array, int fromIndex, int toIndex) { + if (_isEmpty(array.length, fromIndex, toIndex)) + return; + + int outerLimit = toIndex - 1; + for (int i = 0; i < outerLimit; i++) { + int innerLimit = toIndex - i - 1; + for (int j = 0; j < innerLimit; j++) { + int idxB = j + 1; + double a = array[j]; + double b = array[idxB]; + if (a > b) { + array[j] = b; + array[idxB] = a; + } + } + } + } + + private static > void _sortArray(T[] array, int fromIndex, int toIndex) { + if (_isEmpty(array.length, fromIndex, toIndex)) + return; + + int outerLimit = toIndex - 1; + for (int i = 0; i < outerLimit; i++) { + int innerLimit = toIndex - i - 1; + for (int j = 0; j < innerLimit; j++) { + int idxB = j + 1; + T a = array[j]; + T b = array[idxB]; + if (a.compareTo(b) > 0) { + array[j] = b; + array[idxB] = a; + } + } + } + } + + @SuppressWarnings("unchecked") + private static void _sortArray(T[] array, int fromIndex, int toIndex, Comparator comparator) { + if (_isEmpty(array.length, fromIndex, toIndex)) + return; + + int outerLimit = toIndex - 1; + for (int i = 0; i < outerLimit; i++) { + int innerLimit = toIndex - i - 1; + for (int j = 0; j < innerLimit; j++) { + int idxB = j + 1; + T a = array[j]; + T b = array[idxB]; + if (comparator != null && comparator.compare(a, b) > 0 || ((Comparable) a).compareTo(b) > 0) { + array[j] = b; + array[idxB] = a; + } + } + } + } + + @SuppressWarnings("unchecked") + private static void _sortArray(Object[] array, int fromIndex, int toIndex) { + if (_isEmpty(array.length, fromIndex, toIndex)) + return; + + int outerLimit = toIndex - 1; + for (int i = 0; i < outerLimit; i++) { + int innerLimit = toIndex - i - 1; + for (int j = 0; j < innerLimit; j++) { + int idxB = j + 1; + Object a = array[j]; + Object b = array[idxB]; + if (((Comparable) a).compareTo(b) > 0) { + array[j] = b; + array[idxB] = a; + } + } + } + } + + public static void sort(int[] a) { + _checkArrayNull(a); + _sortIntArray(a, 0, a.length); + } + + public static void sort(int[] a, int fromIndex, int toIndex) { + _checkArrayNull(a); + _rangeCheck(a.length, fromIndex, toIndex); + _sortIntArray(a, fromIndex, toIndex); + } + + public static void sort(long[] a) { + _checkArrayNull(a); + _sortLongArray(a, 0, a.length); + } + + public static void sort(long[] a, int fromIndex, int toIndex) { + _checkArrayNull(a); + _rangeCheck(a.length, fromIndex, toIndex); + _sortLongArray(a, fromIndex, toIndex); + } + + public static void sort(short[] a) { + _checkArrayNull(a); + _sortShortArray(a, 0, a.length); + } + + public static void sort(short[] a, int fromIndex, int toIndex) { + _checkArrayNull(a); + _rangeCheck(a.length, fromIndex, toIndex); + _sortShortArray(a, fromIndex, toIndex); + } + + public static void sort(char[] a) { + _checkArrayNull(a); + _sortCharArray(a, 0, a.length); + } + + public static void sort(char[] a, int fromIndex, int toIndex) { + _checkArrayNull(a); + _rangeCheck(a.length, fromIndex, toIndex); + _sortCharArray(a, fromIndex, toIndex); + } + + public static void sort(byte[] a) { + _checkArrayNull(a); + _sortByteArray(a, 0, a.length); + } + + public static void sort(byte[] a, int fromIndex, int toIndex) { + _checkArrayNull(a); + _rangeCheck(a.length, fromIndex, toIndex); + _sortByteArray(a, fromIndex, toIndex); + } + + public static void sort(float[] a) { + _checkArrayNull(a); + _sortFloatArray(a, 0, a.length); + } + + public static void sort(float[] a, int fromIndex, int toIndex) { + _checkArrayNull(a); + _rangeCheck(a.length, fromIndex, toIndex); + _sortFloatArray(a, fromIndex, toIndex); + } + + public static void sort(double[] a) { + _checkArrayNull(a); + _sortDoubleArray(a, 0, a.length); + } + + public static void sort(double[] a, int fromIndex, int toIndex) { + _checkArrayNull(a); + _rangeCheck(a.length, fromIndex, toIndex); + _sortDoubleArray(a, fromIndex, toIndex); + } + + public static void parallelSort(byte[] a) { + _checkArrayNull(a); + _sortByteArray(a, 0, a.length); + } + + public static void parallelSort(byte[] a, int fromIndex, int toIndex) { + _checkArrayNull(a); + _rangeCheck(a.length, fromIndex, toIndex); + _sortByteArray(a, fromIndex, toIndex); + } + + public static void parallelSort(char[] a) { + _checkArrayNull(a); + _sortCharArray(a, 0, a.length); + } + + public static void parallelSort(char[] a, int fromIndex, int toIndex) { + _checkArrayNull(a); + _rangeCheck(a.length, fromIndex, toIndex); + _sortCharArray(a, fromIndex, toIndex); + } + + public static void parallelSort(short[] a) { + _checkArrayNull(a); + _sortShortArray(a, 0, a.length); + } + + public static void parallelSort(short[] a, int fromIndex, int toIndex) { + _checkArrayNull(a); + _rangeCheck(a.length, fromIndex, toIndex); + _sortShortArray(a, fromIndex, toIndex); + } + + public static void parallelSort(int[] a) { + _checkArrayNull(a); + _sortIntArray(a, 0, a.length); + } + + public static void parallelSort(int[] a, int fromIndex, int toIndex) { + _checkArrayNull(a); + _rangeCheck(a.length, fromIndex, toIndex); + _sortIntArray(a, fromIndex, toIndex); + } + + public static void parallelSort(long[] a) { + _checkArrayNull(a); + _sortLongArray(a, 0, a.length); + } + + public static void parallelSort(long[] a, int fromIndex, int toIndex) { + _checkArrayNull(a); + _rangeCheck(a.length, fromIndex, toIndex); + _sortLongArray(a, fromIndex, toIndex); + } + + public static void parallelSort(float[] a) { + _checkArrayNull(a); + _sortFloatArray(a, 0, a.length); + } + + public static void parallelSort(float[] a, int fromIndex, int toIndex) { + _checkArrayNull(a); + _rangeCheck(a.length, fromIndex, toIndex); + _sortFloatArray(a, fromIndex, toIndex); + } + + public static void parallelSort(double[] a) { + _checkArrayNull(a); + _sortDoubleArray(a, 0, a.length); + } + + public static void parallelSort(double[] a, int fromIndex, int toIndex) { + _checkArrayNull(a); + _rangeCheck(a.length, fromIndex, toIndex); + _sortDoubleArray(a, fromIndex, toIndex); + } + + public static > void parallelSort(T[] a) { + _checkArrayNull(a); + _sortArray(a, 0, a.length); + } + + public static > void parallelSort(T[] a, int fromIndex, int toIndex) { + _checkArrayNull(a); + _rangeCheck(a.length, fromIndex, toIndex); + _sortArray(a, fromIndex, toIndex); + } + + public static void parallelSort(T[] a, Comparator cmp) { + _checkArrayNull(a); + _sortArray(a, 0, a.length, cmp); + } + + public static void parallelSort(T[] a, int fromIndex, int toIndex, Comparator cmp) { + _checkArrayNull(a); + _rangeCheck(a.length, fromIndex, toIndex); + _sortArray(a, fromIndex, toIndex, cmp); + } + + public static void sort(Object[] a) { + _checkArrayNull(a); + _sortArray(a, 0, a.length); + } + + public static void sort(Object[] a, int fromIndex, int toIndex) { + _checkArrayNull(a); + _rangeCheck(a.length, fromIndex, toIndex); + _sortArray(a, fromIndex, toIndex); + } + + public static void sort(T[] a, Comparator c) { + _checkArrayNull(a); + _sortArray(a, 0, a.length, c); + } + + public static void sort(T[] a, int fromIndex, int toIndex, Comparator c) { + _checkArrayNull(a); + _rangeCheck(a.length, fromIndex, toIndex); + _sortArray(a, fromIndex, toIndex, c); + } +} diff --git a/approximations/src/main/java/generated/java/util/array/DoubleArrayIteratorImpl.java b/approximations/src/main/java/generated/java/util/array/DoubleArrayIteratorImpl.java new file mode 100644 index 00000000..c2f4d910 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/array/DoubleArrayIteratorImpl.java @@ -0,0 +1,79 @@ +package generated.java.util.array; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import stub.java.util.array.DoubleArrayIterator; + +import java.util.NoSuchElementException; +import java.util.PrimitiveIterator; +import java.util.function.Consumer; +import java.util.function.DoubleConsumer; + +@Approximate(DoubleArrayIterator.class) +public class DoubleArrayIteratorImpl extends AbstractArrayIteratorImpl implements PrimitiveIterator.OfDouble { + + private final double[] storage; + + public DoubleArrayIteratorImpl(double[] storage, int cursor) { + super(cursor); + this.storage = storage; + } + + public DoubleArrayIteratorImpl(double[] storage) { + this(storage, 0); + } + + @SuppressWarnings({"DataFlowIssue", "ConstantValue"}) + private double[] _getStorage() { + double[] storage = this.storage; + Engine.assume(storage != null); + Engine.assume(storage.length >= 0); + return storage; + } + + protected int _getLength() { + return _getStorage().length; + } + + protected Double _getItem(int index) { + return _getStorage()[index]; + } + + public boolean hasNext() { + return super.hasNext(); + } + + public Double next() { + return super.next(); + } + + public double nextDouble() { + if (_isEmpty()) + throw new NoSuchElementException(); + + return _getStorage()[this.cursor++]; + } + + public void remove() { + super.remove(); + } + + public void forEachRemaining(Consumer userAction) { + super.forEachRemaining(userAction); + } + + public void forEachRemaining(DoubleConsumer action) { + if (action == null) + throw new NullPointerException(); + + double[] storage = _getStorage(); + int length = storage.length; + if (this.cursor >= length) + return; + + while (this.cursor < length) { + double item = storage[this.cursor++]; + action.accept(item); + } + } +} diff --git a/approximations/src/main/java/generated/java/util/array/DoubleArraySpliteratorImpl.java b/approximations/src/main/java/generated/java/util/array/DoubleArraySpliteratorImpl.java new file mode 100644 index 00000000..a787c81d --- /dev/null +++ b/approximations/src/main/java/generated/java/util/array/DoubleArraySpliteratorImpl.java @@ -0,0 +1,102 @@ +package generated.java.util.array; + +import java.lang.NullPointerException; +import java.util.Comparator; +import java.util.Spliterator; +import java.util.function.Consumer; +import java.util.function.DoubleConsumer; +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import stub.java.util.array.DoubleArraySpliterator; + +@Approximate(DoubleArraySpliterator.class) +public final class DoubleArraySpliteratorImpl extends AbstractArraySpliteratorImpl implements Spliterator.OfDouble { + + public double[] array; + + public DoubleArraySpliteratorImpl(double[] array, int index, int fence, int characteristics) { + super(index, fence, characteristics); + Engine.assume(array != null); + this.array = array; + } + + public DoubleArraySpliteratorImpl(double[] arr, int additionalCharacteristics) { + this(arr, 0, arr.length, additionalCharacteristics); + } + + protected DoubleArraySpliteratorImpl _create(int index, int fence) { + return new DoubleArraySpliteratorImpl(this.array, index, fence, this.characteristics); + } + + private double[] _getArray() { + double[] array = this.array; + Engine.assume(array != null); + return array; + } + + @SuppressWarnings("DataFlowIssue") + protected Double _getItem(int index) { + Engine.assume(array != null); + return array[index]; + } + + public int characteristics() { + return super.characteristics(); + } + + public long estimateSize() { + return super.estimateSize(); + } + + public void forEachRemaining(DoubleConsumer action) { + if (action == null) + throw new NullPointerException(); + + double[] array = _getArray(); + int current = this.index; + this.index = this.fence; + for (int i = current; i < this.fence; i++) { + double item = array[current]; + action.accept(item); + } + } + + public void forEachRemaining(Consumer action) { + super.forEachRemaining(action); + } + + public Comparator getComparator() { + return super.getComparator(); + } + + public long getExactSizeIfKnown() { + return super.getExactSizeIfKnown(); + } + + public boolean hasCharacteristics(int characteristics) { + return super.hasCharacteristics(characteristics); + } + + public boolean tryAdvance(DoubleConsumer action) { + if (action == null) + throw new NullPointerException(); + + int current = this.index; + if (current < this.fence) { + this.index = current + 1; + double item = _getArray()[current]; + action.accept(item); + return true; + } + + return false; + } + + public boolean tryAdvance(Consumer action) { + return super.tryAdvance(action); + } + + public DoubleArraySpliteratorImpl trySplit() { + return (DoubleArraySpliteratorImpl) super.trySplit(); + } +} diff --git a/approximations/src/main/java/generated/java/util/array/IntArrayIteratorImpl.java b/approximations/src/main/java/generated/java/util/array/IntArrayIteratorImpl.java new file mode 100644 index 00000000..5895b8fe --- /dev/null +++ b/approximations/src/main/java/generated/java/util/array/IntArrayIteratorImpl.java @@ -0,0 +1,79 @@ +package generated.java.util.array; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import stub.java.util.array.IntArrayIterator; + +import java.util.NoSuchElementException; +import java.util.PrimitiveIterator; +import java.util.function.Consumer; +import java.util.function.IntConsumer; + +@Approximate(IntArrayIterator.class) +public class IntArrayIteratorImpl extends AbstractArrayIteratorImpl implements PrimitiveIterator.OfInt { + + private final int[] storage; + + public IntArrayIteratorImpl(int[] storage, int cursor) { + super(cursor); + this.storage = storage; + } + + public IntArrayIteratorImpl(int[] storage) { + this(storage, 0); + } + + @SuppressWarnings({"DataFlowIssue", "ConstantValue"}) + private int[] _getStorage() { + int[] storage = this.storage; + Engine.assume(storage != null); + Engine.assume(storage.length >= 0); + return storage; + } + + protected int _getLength() { + return _getStorage().length; + } + + protected Integer _getItem(int index) { + return _getStorage()[index]; + } + + public boolean hasNext() { + return super.hasNext(); + } + + public Integer next() { + return super.next(); + } + + public int nextInt() { + if (_isEmpty()) + throw new NoSuchElementException(); + + return _getStorage()[this.cursor++]; + } + + public void remove() { + super.remove(); + } + + public void forEachRemaining(Consumer action) { + super.forEachRemaining(action); + } + + public void forEachRemaining(IntConsumer action) { + if (action == null) + throw new NullPointerException(); + + int[] storage = _getStorage(); + int length = storage.length; + if (this.cursor >= length) + return; + + while (this.cursor < length) { + int item = storage[this.cursor++]; + action.accept(item); + } + } +} diff --git a/approximations/src/main/java/generated/java/util/array/IntArraySpliteratorImpl.java b/approximations/src/main/java/generated/java/util/array/IntArraySpliteratorImpl.java new file mode 100644 index 00000000..41c95624 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/array/IntArraySpliteratorImpl.java @@ -0,0 +1,102 @@ +package generated.java.util.array; + +import java.lang.NullPointerException; +import java.util.Comparator; +import java.util.Spliterator; +import java.util.function.Consumer; +import java.util.function.IntConsumer; +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import stub.java.util.array.IntArraySpliterator; + +@Approximate(IntArraySpliterator.class) +public final class IntArraySpliteratorImpl extends AbstractArraySpliteratorImpl implements Spliterator.OfInt { + + public int[] array; + + public IntArraySpliteratorImpl(int[] array, int index, int fence, int characteristics) { + super(index, fence, characteristics); + Engine.assume(array != null); + this.array = array; + } + + public IntArraySpliteratorImpl(int[] arr, int additionalCharacteristics) { + this(arr, 0, arr.length, additionalCharacteristics); + } + + protected IntArraySpliteratorImpl _create(int index, int fence) { + return new IntArraySpliteratorImpl(this.array, index, fence, this.characteristics); + } + + private int[] _getArray() { + int[] array = this.array; + Engine.assume(array != null); + return array; + } + + @SuppressWarnings("DataFlowIssue") + protected Integer _getItem(int index) { + Engine.assume(array != null); + return array[index]; + } + + public int characteristics() { + return super.characteristics(); + } + + public long estimateSize() { + return super.estimateSize(); + } + + public void forEachRemaining(Consumer action) { + super.forEachRemaining(action); + } + + public void forEachRemaining(IntConsumer action) { + if (action == null) + throw new NullPointerException(); + + int[] array = _getArray(); + int current = this.index; + this.index = this.fence; + for (int i = current; i < this.fence; i++) { + int item = array[i]; + action.accept(item); + } + } + + public Comparator getComparator() { + return super.getComparator(); + } + + public long getExactSizeIfKnown() { + return super.getExactSizeIfKnown(); + } + + public boolean hasCharacteristics(int characteristics) { + return super.hasCharacteristics(characteristics); + } + + public boolean tryAdvance(IntConsumer action) { + if (action == null) + throw new NullPointerException(); + + int current = this.index; + if (current < this.fence) { + this.index = current + 1; + int item = _getArray()[current]; + action.accept(item); + return true; + } + + return false; + } + + public boolean tryAdvance(Consumer action) { + return super.tryAdvance(action); + } + + public IntArraySpliteratorImpl trySplit() { + return (IntArraySpliteratorImpl) super.trySplit(); + } +} diff --git a/approximations/src/main/java/generated/java/util/array/LongArrayIteratorImpl.java b/approximations/src/main/java/generated/java/util/array/LongArrayIteratorImpl.java new file mode 100644 index 00000000..4df0d968 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/array/LongArrayIteratorImpl.java @@ -0,0 +1,79 @@ +package generated.java.util.array; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import stub.java.util.array.LongArrayIterator; + +import java.util.NoSuchElementException; +import java.util.PrimitiveIterator; +import java.util.function.Consumer; +import java.util.function.LongConsumer; + +@Approximate(LongArrayIterator.class) +public class LongArrayIteratorImpl extends AbstractArrayIteratorImpl implements PrimitiveIterator.OfLong { + + private final long[] storage; + + public LongArrayIteratorImpl(long[] storage, int cursor) { + super(cursor); + this.storage = storage; + } + + public LongArrayIteratorImpl(long[] storage) { + this(storage, 0); + } + + @SuppressWarnings({"DataFlowIssue", "ConstantValue"}) + private long[] _getStorage() { + long[] storage = this.storage; + Engine.assume(storage != null); + Engine.assume(storage.length >= 0); + return storage; + } + + protected int _getLength() { + return _getStorage().length; + } + + protected Long _getItem(int index) { + return _getStorage()[index]; + } + + public boolean hasNext() { + return super.hasNext(); + } + + public Long next() { + return super.next(); + } + + public long nextLong() { + if (_isEmpty()) + throw new NoSuchElementException(); + + return _getStorage()[this.cursor++]; + } + + public void remove() { + super.remove(); + } + + public void forEachRemaining(Consumer action) { + super.forEachRemaining(action); + } + + public void forEachRemaining(LongConsumer action) { + if (action == null) + throw new NullPointerException(); + + long[] storage = _getStorage(); + int length = storage.length; + if (this.cursor >= length) + return; + + while (this.cursor < length) { + long item = storage[this.cursor++]; + action.accept(item); + } + } +} diff --git a/approximations/src/main/java/generated/java/util/array/LongArraySpliteratorImpl.java b/approximations/src/main/java/generated/java/util/array/LongArraySpliteratorImpl.java new file mode 100644 index 00000000..60f9d15e --- /dev/null +++ b/approximations/src/main/java/generated/java/util/array/LongArraySpliteratorImpl.java @@ -0,0 +1,102 @@ +package generated.java.util.array; + +import java.lang.NullPointerException; +import java.util.Comparator; +import java.util.Spliterator; +import java.util.function.Consumer; +import java.util.function.LongConsumer; +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import stub.java.util.array.LongArraySpliterator; + +@Approximate(LongArraySpliterator.class) +public final class LongArraySpliteratorImpl extends AbstractArraySpliteratorImpl implements Spliterator.OfLong { + + public long[] array; + + public LongArraySpliteratorImpl(long[] array, int index, int fence, int characteristics) { + super(index, fence, characteristics); + Engine.assume(array != null); + this.array = array; + } + + public LongArraySpliteratorImpl(long[] arr, int additionalCharacteristics) { + this(arr, 0, arr.length, additionalCharacteristics); + } + + protected LongArraySpliteratorImpl _create(int index, int fence) { + return new LongArraySpliteratorImpl(this.array, index, fence, this.characteristics); + } + + private long[] _getArray() { + long[] array = this.array; + Engine.assume(array != null); + return array; + } + + @SuppressWarnings("DataFlowIssue") + protected Long _getItem(int index) { + Engine.assume(array != null); + return array[index]; + } + + public int characteristics() { + return super.characteristics(); + } + + public long estimateSize() { + return super.estimateSize(); + } + + public void forEachRemaining(Consumer action) { + super.forEachRemaining(action); + } + + public void forEachRemaining(LongConsumer action) { + if (action == null) + throw new NullPointerException(); + + long[] array = _getArray(); + int current = this.index; + this.index = this.fence; + for (int i = current; i < this.fence; i++) { + long item = array[i]; + action.accept(item); + } + } + + public Comparator getComparator() { + return super.getComparator(); + } + + public long getExactSizeIfKnown() { + return super.getExactSizeIfKnown(); + } + + public boolean hasCharacteristics(int characteristics) { + return super.hasCharacteristics(characteristics); + } + + public boolean tryAdvance(LongConsumer action) { + if (action == null) + throw new NullPointerException(); + + int current = this.index; + if (current < this.fence) { + this.index = current + 1; + long item = _getArray()[current]; + action.accept(item); + return true; + } + + return false; + } + + public boolean tryAdvance(Consumer action) { + return super.tryAdvance(action); + } + + public LongArraySpliteratorImpl trySplit() { + return (LongArraySpliteratorImpl) super.trySplit(); + } +} diff --git a/approximations/src/main/java/generated/java/util/concurrent/atomic/AtomicBoolean.java b/approximations/src/main/java/generated/java/util/concurrent/atomic/AtomicBoolean.java deleted file mode 100644 index 44243bff..00000000 --- a/approximations/src/main/java/generated/java/util/concurrent/atomic/AtomicBoolean.java +++ /dev/null @@ -1,449 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/concurrent/atomic/AtomicBoolean.lsl:24 -// - java/util/concurrent/atomic/AtomicBoolean.main.lsl:17 -// -package generated.java.util.concurrent.atomic; - -import java.io.Serializable; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * AtomicBooleanAutomaton for LSLAtomicBoolean ~> java.util.concurrent.atomic.AtomicBoolean - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.util.concurrent.atomic.AtomicBoolean.class) -public class AtomicBoolean implements LibSLRuntime.Automaton, Serializable { - private static final long serialVersionUID = 4654671469794556979L; - - private static final int FALSE = 0; - - private static final int TRUE = 1; - - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - private volatile int value; - - @LibSLRuntime.AutomatonConstructor - public AtomicBoolean(Void __$lsl_token, final byte p0, final int p1) { - this.__$lsl_state = p0; - this.value = p1; - } - - @LibSLRuntime.AutomatonConstructor - public AtomicBoolean(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, 0); - } - - /** - * [CONSTRUCTOR] AtomicBooleanAutomaton::(LSLAtomicBoolean) -> void - * Source: java/util/concurrent/atomic/AtomicBoolean.main.lsl:64 - */ - public AtomicBoolean() { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.value = FALSE; - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] AtomicBooleanAutomaton::(LSLAtomicBoolean, boolean) -> void - * Source: java/util/concurrent/atomic/AtomicBoolean.main.lsl:70 - */ - public AtomicBoolean(boolean initialValue) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - if (initialValue) { - this.value = TRUE; - } else { - this.value = FALSE; - } - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [FUNCTION] AtomicBooleanAutomaton::compareAndExchange(LSLAtomicBoolean, boolean, boolean) -> boolean - * Source: java/util/concurrent/atomic/AtomicBoolean.main.lsl:83 - */ - public final boolean compareAndExchange(boolean expectedValue, boolean newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value != FALSE; - if (result == expectedValue) { - if (newValue) { - this.value = TRUE; - } else { - this.value = FALSE; - } - } - } - return result; - } - - /** - * [FUNCTION] AtomicBooleanAutomaton::compareAndExchangeAcquire(LSLAtomicBoolean, boolean, boolean) -> boolean - * Source: java/util/concurrent/atomic/AtomicBoolean.main.lsl:96 - */ - public final boolean compareAndExchangeAcquire(boolean expectedValue, boolean newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value != FALSE; - if (result == expectedValue) { - if (newValue) { - this.value = TRUE; - } else { - this.value = FALSE; - } - } - } - return result; - } - - /** - * [FUNCTION] AtomicBooleanAutomaton::compareAndExchangeRelease(LSLAtomicBoolean, boolean, boolean) -> boolean - * Source: java/util/concurrent/atomic/AtomicBoolean.main.lsl:110 - */ - public final boolean compareAndExchangeRelease(boolean expectedValue, boolean newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value != FALSE; - if (result == expectedValue) { - if (newValue) { - this.value = TRUE; - } else { - this.value = FALSE; - } - } - } - return result; - } - - /** - * [FUNCTION] AtomicBooleanAutomaton::compareAndSet(LSLAtomicBoolean, boolean, boolean) -> boolean - * Source: java/util/concurrent/atomic/AtomicBoolean.main.lsl:124 - */ - public final boolean compareAndSet(boolean expectedValue, boolean newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final boolean currentValue = this.value != FALSE; - if (currentValue == expectedValue) { - result = true; - if (newValue) { - this.value = TRUE; - } else { - this.value = FALSE; - } - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] AtomicBooleanAutomaton::get(LSLAtomicBoolean) -> boolean - * Source: java/util/concurrent/atomic/AtomicBoolean.main.lsl:143 - */ - public final boolean get() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value != FALSE; - } - return result; - } - - /** - * [FUNCTION] AtomicBooleanAutomaton::getAcquire(LSLAtomicBoolean) -> boolean - * Source: java/util/concurrent/atomic/AtomicBoolean.main.lsl:150 - */ - public final boolean getAcquire() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value != FALSE; - } - return result; - } - - /** - * [FUNCTION] AtomicBooleanAutomaton::getAndSet(LSLAtomicBoolean, boolean) -> boolean - * Source: java/util/concurrent/atomic/AtomicBoolean.main.lsl:157 - */ - public final boolean getAndSet(boolean newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value != FALSE; - if (newValue) { - this.value = TRUE; - } else { - this.value = FALSE; - } - } - return result; - } - - /** - * [FUNCTION] AtomicBooleanAutomaton::getOpaque(LSLAtomicBoolean) -> boolean - * Source: java/util/concurrent/atomic/AtomicBoolean.main.lsl:168 - */ - public final boolean getOpaque() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value != FALSE; - } - return result; - } - - /** - * [FUNCTION] AtomicBooleanAutomaton::getPlain(LSLAtomicBoolean) -> boolean - * Source: java/util/concurrent/atomic/AtomicBoolean.main.lsl:175 - */ - public final boolean getPlain() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value != FALSE; - } - return result; - } - - /** - * [FUNCTION] AtomicBooleanAutomaton::lazySet(LSLAtomicBoolean, boolean) -> void - * Source: java/util/concurrent/atomic/AtomicBoolean.main.lsl:181 - */ - public final void lazySet(boolean newValue) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (newValue) { - this.value = TRUE; - } else { - this.value = FALSE; - } - } - } - - /** - * [FUNCTION] AtomicBooleanAutomaton::set(LSLAtomicBoolean, boolean) -> void - * Source: java/util/concurrent/atomic/AtomicBoolean.main.lsl:191 - */ - public final void set(boolean newValue) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (newValue) { - this.value = TRUE; - } else { - this.value = FALSE; - } - } - } - - /** - * [FUNCTION] AtomicBooleanAutomaton::setOpaque(LSLAtomicBoolean, boolean) -> void - * Source: java/util/concurrent/atomic/AtomicBoolean.main.lsl:200 - */ - public final void setOpaque(boolean newValue) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (newValue) { - this.value = TRUE; - } else { - this.value = FALSE; - } - } - } - - /** - * [FUNCTION] AtomicBooleanAutomaton::setPlain(LSLAtomicBoolean, boolean) -> void - * Source: java/util/concurrent/atomic/AtomicBoolean.main.lsl:210 - */ - public final void setPlain(boolean newValue) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (newValue) { - this.value = TRUE; - } else { - this.value = FALSE; - } - } - } - - /** - * [FUNCTION] AtomicBooleanAutomaton::setRelease(LSLAtomicBoolean, boolean) -> void - * Source: java/util/concurrent/atomic/AtomicBoolean.main.lsl:220 - */ - public final void setRelease(boolean newValue) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (newValue) { - this.value = TRUE; - } else { - this.value = FALSE; - } - } - } - - /** - * [FUNCTION] AtomicBooleanAutomaton::toString(LSLAtomicBoolean) -> String - * Source: java/util/concurrent/atomic/AtomicBoolean.main.lsl:230 - */ - public String toString() { - String result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.value == FALSE) { - result = "false"; - } else { - result = "true"; - } - } - return result; - } - - /** - * [FUNCTION] AtomicBooleanAutomaton::weakCompareAndSet(LSLAtomicBoolean, boolean, boolean) -> boolean - * Source: java/util/concurrent/atomic/AtomicBoolean.main.lsl:239 - */ - public boolean weakCompareAndSet(boolean expectedValue, boolean newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final boolean currentValue = this.value != FALSE; - if (currentValue == expectedValue) { - result = true; - if (newValue) { - this.value = TRUE; - } else { - this.value = FALSE; - } - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] AtomicBooleanAutomaton::weakCompareAndSetAcquire(LSLAtomicBoolean, boolean, boolean) -> boolean - * Source: java/util/concurrent/atomic/AtomicBoolean.main.lsl:259 - */ - public final boolean weakCompareAndSetAcquire(boolean expectedValue, boolean newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final boolean currentValue = this.value != FALSE; - if (currentValue == expectedValue) { - result = true; - if (newValue) { - this.value = TRUE; - } else { - this.value = FALSE; - } - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] AtomicBooleanAutomaton::weakCompareAndSetPlain(LSLAtomicBoolean, boolean, boolean) -> boolean - * Source: java/util/concurrent/atomic/AtomicBoolean.main.lsl:279 - */ - public boolean weakCompareAndSetPlain(boolean expectedValue, boolean newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final boolean currentValue = this.value != FALSE; - if (currentValue == expectedValue) { - result = true; - if (newValue) { - this.value = TRUE; - } else { - this.value = FALSE; - } - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] AtomicBooleanAutomaton::weakCompareAndSetRelease(LSLAtomicBoolean, boolean, boolean) -> boolean - * Source: java/util/concurrent/atomic/AtomicBoolean.main.lsl:299 - */ - public final boolean weakCompareAndSetRelease(boolean expectedValue, boolean newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final boolean currentValue = this.value != FALSE; - if (currentValue == expectedValue) { - result = true; - if (newValue) { - this.value = TRUE; - } else { - this.value = FALSE; - } - } else { - result = false; - } - } - return result; - } - - /** - * [FUNCTION] AtomicBooleanAutomaton::weakCompareAndSetVolatile(LSLAtomicBoolean, boolean, boolean) -> boolean - * Source: java/util/concurrent/atomic/AtomicBoolean.main.lsl:319 - */ - public final boolean weakCompareAndSetVolatile(boolean expectedValue, boolean newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final boolean currentValue = this.value != FALSE; - if (currentValue == expectedValue) { - result = true; - if (newValue) { - this.value = TRUE; - } else { - this.value = FALSE; - } - } else { - result = false; - } - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(AtomicBoolean.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/concurrent/atomic/AtomicBooleanImpl.java b/approximations/src/main/java/generated/java/util/concurrent/atomic/AtomicBooleanImpl.java new file mode 100644 index 00000000..b79497d4 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/concurrent/atomic/AtomicBooleanImpl.java @@ -0,0 +1,137 @@ +package generated.java.util.concurrent.atomic; + +import java.io.Serial; +import java.io.Serializable; +import java.lang.String; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; + +@SuppressWarnings("unused") +@Approximate(java.util.concurrent.atomic.AtomicBoolean.class) +public class AtomicBooleanImpl implements Serializable { + + @Serial + private static final long serialVersionUID = 4654671469794556979L; + + private static final int FALSE = 0; + + private static final int TRUE = 1; + + static { + Engine.assume(true); + } + + private volatile int value; + + public AtomicBooleanImpl(int value) { + this.value = value; + } + + public AtomicBooleanImpl() { + this(FALSE); + } + + private static int _valueFromBool(boolean value) { + return value ? TRUE : FALSE; + } + + public AtomicBooleanImpl(boolean initialValue) { + this(_valueFromBool(initialValue)); + } + + public final boolean compareAndExchange(boolean expectedValue, boolean newValue) { + boolean result = get(); + if (result == expectedValue) + set(newValue); + + return result; + } + + public final boolean compareAndExchangeAcquire(boolean expectedValue, boolean newValue) { + return compareAndExchange(expectedValue, newValue); + } + + public final boolean compareAndExchangeRelease(boolean expectedValue, boolean newValue) { + return compareAndExchange(expectedValue, newValue); + } + + public final boolean compareAndSet(boolean expectedValue, boolean newValue) { + boolean currentValue = get(); + if (currentValue != expectedValue) + return false; + + set(newValue); + return true; + } + + public final boolean get() { + return this.value != FALSE; + } + + public final boolean getAcquire() { + return get(); + } + + public final boolean getAndSet(boolean newValue) { + boolean result = get(); + set(newValue); + + return result; + } + + public final boolean getOpaque() { + return get(); + } + + public final boolean getPlain() { + return get(); + } + + public final void set(boolean newValue) { + this.value = _valueFromBool(newValue); + } + + public final void lazySet(boolean newValue) { + set(newValue); + } + + public final void setOpaque(boolean newValue) { + set(newValue); + } + + public final void setPlain(boolean newValue) { + set(newValue); + } + + public final void setRelease(boolean newValue) { + set(newValue); + } + + public String toString() { + if (this.value == TRUE) + return "true"; + + return "false"; + } + + public boolean weakCompareAndSet(boolean expectedValue, boolean newValue) { + return compareAndSet(expectedValue, newValue); + } + + public final boolean weakCompareAndSetAcquire(boolean expectedValue, boolean newValue) { + return compareAndSet(expectedValue, newValue); + } + + public boolean weakCompareAndSetPlain(boolean expectedValue, boolean newValue) { + return compareAndSet(expectedValue, newValue); + } + + public final boolean weakCompareAndSetRelease(boolean expectedValue, boolean newValue) { + return compareAndSet(expectedValue, newValue); + } + + public final boolean weakCompareAndSetVolatile(boolean expectedValue, boolean newValue) { + return compareAndSet(expectedValue, newValue); + } +} diff --git a/approximations/src/main/java/generated/java/util/concurrent/atomic/AtomicInteger.java b/approximations/src/main/java/generated/java/util/concurrent/atomic/AtomicInteger.java deleted file mode 100644 index db6e0e55..00000000 --- a/approximations/src/main/java/generated/java/util/concurrent/atomic/AtomicInteger.java +++ /dev/null @@ -1,579 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/concurrent/atomic/AtomicInteger.lsl:25 -// - java/util/concurrent/atomic/AtomicInteger.main.lsl:20 -// -package generated.java.util.concurrent.atomic; - -import java.io.Serializable; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.function.IntBinaryOperator; -import java.util.function.IntUnaryOperator; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * AtomicIntegerAutomaton for LSLAtomicInteger ~> java.util.concurrent.atomic.AtomicInteger - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(java.util.concurrent.atomic.AtomicInteger.class) -public class AtomicInteger implements LibSLRuntime.Automaton, Serializable { - private static final long serialVersionUID = 6214790243416807050L; - - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - private volatile int value; - - @LibSLRuntime.AutomatonConstructor - public AtomicInteger(Void __$lsl_token, final byte p0, final int p1) { - this.__$lsl_state = p0; - this.value = p1; - } - - @LibSLRuntime.AutomatonConstructor - public AtomicInteger(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, 0); - } - - /** - * [CONSTRUCTOR] AtomicIntegerAutomaton::(LSLAtomicInteger) -> void - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:83 - */ - public AtomicInteger() { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.value = 0; - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] AtomicIntegerAutomaton::(LSLAtomicInteger, int) -> void - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:89 - */ - public AtomicInteger(int initialValue) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.value = initialValue; - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::accumulateAndGet(LSLAtomicInteger, int, IntBinaryOperator) -> int - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:99 - */ - public final int accumulateAndGet(int x, IntBinaryOperator accumulatorFunction) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = accumulatorFunction.applyAsInt(this.value, x); - this.value = result; - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::addAndGet(LSLAtomicInteger, int) -> int - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:106 - */ - public final int addAndGet(int delta) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value + delta; - this.value = result; - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::byteValue(LSLAtomicInteger) -> byte - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:114 - */ - public byte byteValue() { - byte result = ((byte) 0); - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((byte) this.value); - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::compareAndExchange(LSLAtomicInteger, int, int) -> int - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:120 - */ - public final int compareAndExchange(int expectedValue, int newValue) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - if (result == expectedValue) { - this.value = newValue; - } - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::compareAndExchangeAcquire(LSLAtomicInteger, int, int) -> int - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:128 - */ - public final int compareAndExchangeAcquire(int expectedValue, int newValue) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - if (result == expectedValue) { - this.value = newValue; - } - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::compareAndExchangeRelease(LSLAtomicInteger, int, int) -> int - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:137 - */ - public final int compareAndExchangeRelease(int expectedValue, int newValue) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - if (result == expectedValue) { - this.value = newValue; - } - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::compareAndSet(LSLAtomicInteger, int, int) -> boolean - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:146 - */ - public final boolean compareAndSet(int expectedValue, int newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value == expectedValue; - if (result) { - this.value = newValue; - } - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::decrementAndGet(LSLAtomicInteger) -> int - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:154 - */ - public final int decrementAndGet() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value - 1; - this.value = result; - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::doubleValue(LSLAtomicInteger) -> double - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:161 - */ - public double doubleValue() { - double result = 0.0d; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((double) this.value); - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::floatValue(LSLAtomicInteger) -> float - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:167 - */ - public float floatValue() { - float result = 0.0f; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((float) this.value); - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::get(LSLAtomicInteger) -> int - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:173 - */ - public final int get() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::getAcquire(LSLAtomicInteger) -> int - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:179 - */ - public final int getAcquire() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::getAndAccumulate(LSLAtomicInteger, int, IntBinaryOperator) -> int - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:186 - */ - public final int getAndAccumulate(int x, IntBinaryOperator accumulatorFunction) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - this.value = accumulatorFunction.applyAsInt(result, x); - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::getAndAdd(LSLAtomicInteger, int) -> int - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:193 - */ - public final int getAndAdd(int delta) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - this.value = result + delta; - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::getAndDecrement(LSLAtomicInteger) -> int - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:200 - */ - public final int getAndDecrement() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - this.value = result - 1; - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::getAndIncrement(LSLAtomicInteger) -> int - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:207 - */ - public final int getAndIncrement() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - this.value = result + 1; - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::getAndSet(LSLAtomicInteger, int) -> int - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:214 - */ - public final int getAndSet(int newValue) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - this.value = newValue; - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::getAndUpdate(LSLAtomicInteger, IntUnaryOperator) -> int - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:221 - */ - public final int getAndUpdate(IntUnaryOperator updateFunction) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - this.value = updateFunction.applyAsInt(result); - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::getOpaque(LSLAtomicInteger) -> int - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:228 - */ - public final int getOpaque() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::getPlain(LSLAtomicInteger) -> int - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:235 - */ - public final int getPlain() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::incrementAndGet(LSLAtomicInteger) -> int - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:242 - */ - public final int incrementAndGet() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value + 1; - this.value = result; - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::intValue(LSLAtomicInteger) -> int - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:249 - */ - public int intValue() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::lazySet(LSLAtomicInteger, int) -> void - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:255 - */ - public final void lazySet(int newValue) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.value = newValue; - } - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::longValue(LSLAtomicInteger) -> long - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:262 - */ - public long longValue() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((long) this.value); - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::set(LSLAtomicInteger, int) -> void - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:268 - */ - public final void set(int newValue) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.value = newValue; - } - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::setOpaque(LSLAtomicInteger, int) -> void - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:274 - */ - public final void setOpaque(int newValue) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.value = newValue; - } - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::setPlain(LSLAtomicInteger, int) -> void - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:281 - */ - public final void setPlain(int newValue) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.value = newValue; - } - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::setRelease(LSLAtomicInteger, int) -> void - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:288 - */ - public final void setRelease(int newValue) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.value = newValue; - } - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::shortValue(LSLAtomicInteger) -> short - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:296 - */ - public short shortValue() { - short result = ((short) 0); - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((short) this.value); - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::toString(LSLAtomicInteger) -> String - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:302 - */ - public String toString() { - String result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = LibSLRuntime.toString(this.value); - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::updateAndGet(LSLAtomicInteger, IntUnaryOperator) -> int - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:308 - */ - public final int updateAndGet(IntUnaryOperator updateFunction) { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = updateFunction.applyAsInt(this.value); - this.value = result; - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::weakCompareAndSet(LSLAtomicInteger, int, int) -> boolean - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:315 - */ - public final boolean weakCompareAndSet(int expectedValue, int newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value == expectedValue; - if (result) { - this.value = newValue; - } - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::weakCompareAndSetAcquire(LSLAtomicInteger, int, int) -> boolean - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:324 - */ - public final boolean weakCompareAndSetAcquire(int expectedValue, int newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value == expectedValue; - if (result) { - this.value = newValue; - } - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::weakCompareAndSetPlain(LSLAtomicInteger, int, int) -> boolean - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:333 - */ - public final boolean weakCompareAndSetPlain(int expectedValue, int newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value == expectedValue; - if (result) { - this.value = newValue; - } - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::weakCompareAndSetRelease(LSLAtomicInteger, int, int) -> boolean - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:342 - */ - public final boolean weakCompareAndSetRelease(int expectedValue, int newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value == expectedValue; - if (result) { - this.value = newValue; - } - } - return result; - } - - /** - * [FUNCTION] AtomicIntegerAutomaton::weakCompareAndSetVolatile(LSLAtomicInteger, int, int) -> boolean - * Source: java/util/concurrent/atomic/AtomicInteger.main.lsl:351 - */ - public final boolean weakCompareAndSetVolatile(int expectedValue, int newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value == expectedValue; - if (result) { - this.value = newValue; - } - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(AtomicInteger.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/concurrent/atomic/AtomicIntegerImpl.java b/approximations/src/main/java/generated/java/util/concurrent/atomic/AtomicIntegerImpl.java new file mode 100644 index 00000000..06d48d30 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/concurrent/atomic/AtomicIntegerImpl.java @@ -0,0 +1,213 @@ +package generated.java.util.concurrent.atomic; + +import java.io.Serial; +import java.io.Serializable; +import java.lang.String; +import java.util.function.IntBinaryOperator; +import java.util.function.IntUnaryOperator; +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +@SuppressWarnings("unused") +@Approximate(java.util.concurrent.atomic.AtomicInteger.class) +public class AtomicIntegerImpl implements Serializable { + + @Serial + private static final long serialVersionUID = 6214790243416807050L; + + static { + Engine.assume(true); + } + + private volatile int value; + + public AtomicIntegerImpl(int initialValue) { + this.value = initialValue; + } + + public AtomicIntegerImpl() { + this(0); + } + + public final int accumulateAndGet(int x, IntBinaryOperator accumulatorFunction) { + int result = accumulatorFunction.applyAsInt(this.value, x); + this.value = result; + return result; + } + + public final int addAndGet(int delta) { + int result = this.value + delta; + this.value = result; + return result; + } + + public byte byteValue() { + return (byte) this.value; + } + + public final int compareAndExchange(int expectedValue, int newValue) { + int result = this.value; + if (result == expectedValue) + this.value = newValue; + + return result; + } + + public final int compareAndExchangeAcquire(int expectedValue, int newValue) { + return compareAndExchange(expectedValue, newValue); + } + + public final int compareAndExchangeRelease(int expectedValue, int newValue) { + return compareAndExchange(expectedValue, newValue); + } + + public final boolean compareAndSet(int expectedValue, int newValue) { + boolean result = this.value == expectedValue; + if (result) + this.value = newValue; + + return result; + } + + public final int decrementAndGet() { + int result = this.value - 1; + this.value = result; + return result; + } + + public double doubleValue() { + return this.value; + } + + public float floatValue() { + return this.value; + } + + public final int get() { + return this.value; + } + + public final int getAcquire() { + return this.value; + } + + public final int getAndAccumulate(int x, IntBinaryOperator accumulatorFunction) { + int result = this.value; + this.value = accumulatorFunction.applyAsInt(result, x); + return result; + } + + public final int getAndAdd(int delta) { + int result = this.value; + this.value = result + delta; + + return result; + } + + public final int getAndDecrement() { + int result = this.value; + this.value = result - 1; + + return result; + } + + public final int getAndIncrement() { + int result = this.value; + this.value = result + 1; + + return result; + } + + public final int getAndSet(int newValue) { + int result = this.value; + this.value = newValue; + + return result; + } + + public final int getAndUpdate(IntUnaryOperator updateFunction) { + int result = this.value; + this.value = updateFunction.applyAsInt(result); + + return result; + } + + public final int getOpaque() { + return this.value; + } + + public final int getPlain() { + return this.value; + } + + public final int incrementAndGet() { + int result = this.value + 1; + this.value = result; + + return result; + } + + public int intValue() { + return this.value; + } + + public final void lazySet(int newValue) { + this.value = newValue; + } + + public long longValue() { + return this.value; + } + + public final void set(int newValue) { + this.value = newValue; + } + + public final void setOpaque(int newValue) { + this.value = newValue; + } + + public final void setPlain(int newValue) { + this.value = newValue; + } + + public final void setRelease(int newValue) { + this.value = newValue; + } + + public short shortValue() { + return (short) this.value; + } + + public String toString() { + return LibSLRuntime.toString(this.value); + } + + public final int updateAndGet(IntUnaryOperator updateFunction) { + int result = updateFunction.applyAsInt(this.value); + this.value = result; + + return result; + } + + public final boolean weakCompareAndSet(int expectedValue, int newValue) { + return compareAndSet(expectedValue, newValue); + } + + public final boolean weakCompareAndSetAcquire(int expectedValue, int newValue) { + return compareAndSet(expectedValue, newValue); + } + + public final boolean weakCompareAndSetPlain(int expectedValue, int newValue) { + return compareAndSet(expectedValue, newValue); + } + + public final boolean weakCompareAndSetRelease(int expectedValue, int newValue) { + return compareAndSet(expectedValue, newValue); + } + + public final boolean weakCompareAndSetVolatile(int expectedValue, int newValue) { + return compareAndSet(expectedValue, newValue); + } +} diff --git a/approximations/src/main/java/generated/java/util/concurrent/atomic/AtomicLong.java b/approximations/src/main/java/generated/java/util/concurrent/atomic/AtomicLong.java index b9304964..45afbbbc 100644 --- a/approximations/src/main/java/generated/java/util/concurrent/atomic/AtomicLong.java +++ b/approximations/src/main/java/generated/java/util/concurrent/atomic/AtomicLong.java @@ -1,579 +1,218 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/concurrent/atomic/AtomicLong.lsl:25 -// - java/util/concurrent/atomic/AtomicLong.main.lsl:20 -// package generated.java.util.concurrent.atomic; +import java.io.Serial; import java.io.Serializable; import java.lang.String; import java.lang.SuppressWarnings; -import java.lang.Void; import java.util.function.LongBinaryOperator; import java.util.function.LongUnaryOperator; import org.jacodb.approximation.annotation.Approximate; import org.usvm.api.Engine; import runtime.LibSLRuntime; -/** - * AtomicLongAutomaton for LSLAtomicLong ~> java.util.concurrent.atomic.AtomicLong - */ -@SuppressWarnings({"all", "unchecked"}) +@SuppressWarnings("unused") @Approximate(java.util.concurrent.atomic.AtomicLong.class) -public class AtomicLong implements LibSLRuntime.Automaton, Serializable { +public class AtomicLong implements Serializable { + + @Serial private static final long serialVersionUID = 1927816293512124184L; static { Engine.assume(true); } - private byte __$lsl_state = __$lsl_States.Allocated; - private volatile long value; - @LibSLRuntime.AutomatonConstructor - public AtomicLong(Void __$lsl_token, final byte p0, final long p1) { - this.__$lsl_state = p0; - this.value = p1; + public AtomicLong(long initialValue) { + this.value = initialValue; } - @LibSLRuntime.AutomatonConstructor - public AtomicLong(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, 0L); + public AtomicLong() { + this(0L); } - /** - * [CONSTRUCTOR] AtomicLongAutomaton::(LSLAtomicLong) -> void - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:83 - */ - public AtomicLong() { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.value = 0L; - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [CONSTRUCTOR] AtomicLongAutomaton::(LSLAtomicLong, long) -> void - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:89 - */ - public AtomicLong(long initialValue) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.value = initialValue; - } - this.__$lsl_state = __$lsl_States.Initialized; - } - - /** - * [FUNCTION] AtomicLongAutomaton::accumulateAndGet(LSLAtomicLong, long, LongBinaryOperator) -> long - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:99 - */ public final long accumulateAndGet(long x, LongBinaryOperator accumulatorFunction) { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = accumulatorFunction.applyAsLong(this.value, x); - this.value = result; - } + long result = accumulatorFunction.applyAsLong(this.value, x); + this.value = result; + return result; } - /** - * [FUNCTION] AtomicLongAutomaton::addAndGet(LSLAtomicLong, long) -> long - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:106 - */ public final long addAndGet(long delta) { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value + delta; - this.value = result; - } + long result = this.value + delta; + this.value = result; + return result; } - /** - * [FUNCTION] AtomicLongAutomaton::byteValue(LSLAtomicLong) -> byte - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:114 - */ public byte byteValue() { - byte result = ((byte) 0); - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((byte) this.value); - } - return result; + return (byte) this.value; } - /** - * [FUNCTION] AtomicLongAutomaton::compareAndExchange(LSLAtomicLong, long, long) -> long - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:120 - */ public final long compareAndExchange(long expectedValue, long newValue) { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - if (result == expectedValue) { - this.value = newValue; - } - } + long result = this.value; + if (result == expectedValue) + this.value = newValue; + return result; } - /** - * [FUNCTION] AtomicLongAutomaton::compareAndExchangeAcquire(LSLAtomicLong, long, long) -> long - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:128 - */ public final long compareAndExchangeAcquire(long expectedValue, long newValue) { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - if (result == expectedValue) { - this.value = newValue; - } - } - return result; + return compareAndExchange(expectedValue, newValue); } - /** - * [FUNCTION] AtomicLongAutomaton::compareAndExchangeRelease(LSLAtomicLong, long, long) -> long - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:137 - */ public final long compareAndExchangeRelease(long expectedValue, long newValue) { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - if (result == expectedValue) { - this.value = newValue; - } - } - return result; + return compareAndExchange(expectedValue, newValue); } - /** - * [FUNCTION] AtomicLongAutomaton::compareAndSet(LSLAtomicLong, long, long) -> boolean - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:146 - */ public final boolean compareAndSet(long expectedValue, long newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value == expectedValue; - if (result) { - this.value = newValue; - } - } + boolean result = this.value == expectedValue; + if (result) + this.value = newValue; + return result; } - /** - * [FUNCTION] AtomicLongAutomaton::decrementAndGet(LSLAtomicLong) -> long - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:154 - */ public final long decrementAndGet() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value - 1L; - this.value = result; - } + long result = this.value - 1L; + this.value = result; + return result; } - /** - * [FUNCTION] AtomicLongAutomaton::doubleValue(LSLAtomicLong) -> double - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:161 - */ public double doubleValue() { - double result = 0.0d; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((double) this.value); - } - return result; + return (double) this.value; } - /** - * [FUNCTION] AtomicLongAutomaton::floatValue(LSLAtomicLong) -> float - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:167 - */ public float floatValue() { - float result = 0.0f; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((float) this.value); - } - return result; + return (float) this.value; } - /** - * [FUNCTION] AtomicLongAutomaton::get(LSLAtomicLong) -> long - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:173 - */ public final long get() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - } - return result; + return this.value; } - /** - * [FUNCTION] AtomicLongAutomaton::getAcquire(LSLAtomicLong) -> long - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:179 - */ public final long getAcquire() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - } - return result; + return this.value; } - /** - * [FUNCTION] AtomicLongAutomaton::getAndAccumulate(LSLAtomicLong, long, LongBinaryOperator) -> long - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:186 - */ public final long getAndAccumulate(long x, LongBinaryOperator accumulatorFunction) { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - this.value = accumulatorFunction.applyAsLong(result, x); - } + long result = this.value; + this.value = accumulatorFunction.applyAsLong(result, x); + return result; } - /** - * [FUNCTION] AtomicLongAutomaton::getAndAdd(LSLAtomicLong, long) -> long - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:193 - */ public final long getAndAdd(long delta) { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - this.value = result + delta; - } + long result = this.value; + this.value = result + delta; + return result; } - /** - * [FUNCTION] AtomicLongAutomaton::getAndDecrement(LSLAtomicLong) -> long - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:200 - */ public final long getAndDecrement() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - this.value = result - 1L; - } + long result = this.value; + this.value = result - 1L; + return result; } - /** - * [FUNCTION] AtomicLongAutomaton::getAndIncrement(LSLAtomicLong) -> long - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:207 - */ public final long getAndIncrement() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - this.value = result + 1L; - } + long result = this.value; + this.value = result + 1L; + return result; } - /** - * [FUNCTION] AtomicLongAutomaton::getAndSet(LSLAtomicLong, long) -> long - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:214 - */ public final long getAndSet(long newValue) { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - this.value = newValue; - } + long result = this.value; + this.value = newValue; + return result; } - /** - * [FUNCTION] AtomicLongAutomaton::getAndUpdate(LSLAtomicLong, LongUnaryOperator) -> long - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:221 - */ public final long getAndUpdate(LongUnaryOperator updateFunction) { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - this.value = updateFunction.applyAsLong(result); - } + long result = this.value; + this.value = updateFunction.applyAsLong(result); + return result; } - /** - * [FUNCTION] AtomicLongAutomaton::getOpaque(LSLAtomicLong) -> long - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:228 - */ public final long getOpaque() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - } - return result; + return this.value; } - /** - * [FUNCTION] AtomicLongAutomaton::getPlain(LSLAtomicLong) -> long - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:235 - */ public final long getPlain() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - } - return result; + return this.value; } - /** - * [FUNCTION] AtomicLongAutomaton::incrementAndGet(LSLAtomicLong) -> long - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:242 - */ public final long incrementAndGet() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value + 1L; - this.value = result; - } - return result; - } + long result = this.value + 1L; + this.value = result; - /** - * [FUNCTION] AtomicLongAutomaton::intValue(LSLAtomicLong) -> int - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:249 - */ - public int intValue() { - int result = 0; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((int) this.value); - } return result; } - /** - * [FUNCTION] AtomicLongAutomaton::lazySet(LSLAtomicLong, long) -> void - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:255 - */ - public final void lazySet(long newValue) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.value = newValue; - } + public int intValue() { + return (int) this.value; } - /** - * [FUNCTION] AtomicLongAutomaton::longValue(LSLAtomicLong) -> long - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:262 - */ public long longValue() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - } - return result; + return this.value; } - /** - * [FUNCTION] AtomicLongAutomaton::set(LSLAtomicLong, long) -> void - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:268 - */ public final void set(long newValue) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.value = newValue; - } + this.value = newValue; + } + + public final void lazySet(long newValue) { + set(newValue); } - /** - * [FUNCTION] AtomicLongAutomaton::setOpaque(LSLAtomicLong, long) -> void - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:274 - */ public final void setOpaque(long newValue) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.value = newValue; - } + set(newValue); } - /** - * [FUNCTION] AtomicLongAutomaton::setPlain(LSLAtomicLong, long) -> void - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:281 - */ public final void setPlain(long newValue) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.value = newValue; - } + set(newValue); } - /** - * [FUNCTION] AtomicLongAutomaton::setRelease(LSLAtomicLong, long) -> void - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:288 - */ public final void setRelease(long newValue) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.value = newValue; - } + set(newValue); } - /** - * [FUNCTION] AtomicLongAutomaton::shortValue(LSLAtomicLong) -> short - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:296 - */ public short shortValue() { - short result = ((short) 0); - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((short) this.value); - } - return result; + return (short) this.value; } - /** - * [FUNCTION] AtomicLongAutomaton::toString(LSLAtomicLong) -> String - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:302 - */ public String toString() { - String result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = LibSLRuntime.toString(this.value); - } - return result; + return LibSLRuntime.toString(this.value); } - /** - * [FUNCTION] AtomicLongAutomaton::updateAndGet(LSLAtomicLong, LongUnaryOperator) -> long - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:308 - */ public final long updateAndGet(LongUnaryOperator updateFunction) { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = updateFunction.applyAsLong(this.value); - this.value = result; - } + long result = updateFunction.applyAsLong(this.value); + this.value = result; + return result; } - /** - * [FUNCTION] AtomicLongAutomaton::weakCompareAndSet(LSLAtomicLong, long, long) -> boolean - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:315 - */ public final boolean weakCompareAndSet(long expectedValue, long newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value == expectedValue; - if (result) { - this.value = newValue; - } - } - return result; + return compareAndSet(expectedValue, newValue); } - /** - * [FUNCTION] AtomicLongAutomaton::weakCompareAndSetAcquire(LSLAtomicLong, long, long) -> boolean - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:324 - */ public final boolean weakCompareAndSetAcquire(long expectedValue, long newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value == expectedValue; - if (result) { - this.value = newValue; - } - } - return result; + return compareAndSet(expectedValue, newValue); } - /** - * [FUNCTION] AtomicLongAutomaton::weakCompareAndSetPlain(LSLAtomicLong, long, long) -> boolean - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:333 - */ public final boolean weakCompareAndSetPlain(long expectedValue, long newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value == expectedValue; - if (result) { - this.value = newValue; - } - } - return result; + return compareAndSet(expectedValue, newValue); } - /** - * [FUNCTION] AtomicLongAutomaton::weakCompareAndSetRelease(LSLAtomicLong, long, long) -> boolean - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:342 - */ public final boolean weakCompareAndSetRelease(long expectedValue, long newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value == expectedValue; - if (result) { - this.value = newValue; - } - } - return result; + return compareAndSet(expectedValue, newValue); } - /** - * [FUNCTION] AtomicLongAutomaton::weakCompareAndSetVolatile(LSLAtomicLong, long, long) -> boolean - * Source: java/util/concurrent/atomic/AtomicLong.main.lsl:351 - */ public final boolean weakCompareAndSetVolatile(long expectedValue, long newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value == expectedValue; - if (result) { - this.value = newValue; - } - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(AtomicLong.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } + return compareAndSet(expectedValue, newValue); } } diff --git a/approximations/src/main/java/generated/java/util/concurrent/atomic/AtomicReference.java b/approximations/src/main/java/generated/java/util/concurrent/atomic/AtomicReference.java index 9c8748bd..d8d8dc73 100644 --- a/approximations/src/main/java/generated/java/util/concurrent/atomic/AtomicReference.java +++ b/approximations/src/main/java/generated/java/util/concurrent/atomic/AtomicReference.java @@ -1,418 +1,153 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/concurrent/atomic/AtomicReference.lsl:24 -// - java/util/concurrent/atomic/AtomicReference.main.lsl:21 -// package generated.java.util.concurrent.atomic; +import java.io.Serial; import java.io.Serializable; import java.lang.Object; import java.lang.String; import java.lang.SuppressWarnings; -import java.lang.Void; import java.util.function.BinaryOperator; import java.util.function.UnaryOperator; import org.jacodb.approximation.annotation.Approximate; import org.usvm.api.Engine; import runtime.LibSLRuntime; -/** - * AtomicReferenceAutomaton for LSLAtomicReference ~> java.util.concurrent.atomic.AtomicReference - */ -@SuppressWarnings({"all", "unchecked"}) +@SuppressWarnings("unused") @Approximate(java.util.concurrent.atomic.AtomicReference.class) -public class AtomicReference implements LibSLRuntime.Automaton, Serializable { +public class AtomicReference implements Serializable { + + @Serial private static final long serialVersionUID = -1848883965231344442L; static { Engine.assume(true); } - private byte __$lsl_state = __$lsl_States.Allocated; - - private volatile Object value; + private transient volatile Object value; - @LibSLRuntime.AutomatonConstructor - public AtomicReference(Void __$lsl_token, final byte p0, final Object p1) { - this.__$lsl_state = p0; - this.value = p1; + public AtomicReference(Object obj) { + this.value = obj; } - @LibSLRuntime.AutomatonConstructor - public AtomicReference(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, null); - } - - /** - * [CONSTRUCTOR] AtomicReferenceAutomaton::(LSLAtomicReference) -> void - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:72 - */ public AtomicReference() { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.value = null; - } - this.__$lsl_state = __$lsl_States.Initialized; + this(null); } - /** - * [CONSTRUCTOR] AtomicReferenceAutomaton::(LSLAtomicReference, Object) -> void - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:78 - */ - public AtomicReference(Object initialValue) { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - this.value = initialValue; - } - this.__$lsl_state = __$lsl_States.Initialized; - } + public final Object accumulateAndGet(Object x, BinaryOperator accumulatorFunction) { + Object result = accumulatorFunction.apply(this.value, x); + this.value = result; - /** - * [FUNCTION] AtomicReferenceAutomaton::accumulateAndGet(LSLAtomicReference, Object, BinaryOperator) -> Object - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:88 - */ - public final Object accumulateAndGet(Object x, BinaryOperator accumulatorFunction) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = accumulatorFunction.apply(this.value, x); - this.value = result; - } return result; } - /** - * [FUNCTION] AtomicReferenceAutomaton::compareAndExchange(LSLAtomicReference, Object, Object) -> Object - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:95 - */ public final Object compareAndExchange(Object expectedValue, Object newValue) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - if (result == expectedValue) { - this.value = newValue; - } - } + Object result = this.value; + if (result == expectedValue) + this.value = newValue; + return result; } - /** - * [FUNCTION] AtomicReferenceAutomaton::compareAndExchangeAcquire(LSLAtomicReference, Object, Object) -> Object - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:103 - */ public final Object compareAndExchangeAcquire(Object expectedValue, Object newValue) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - if (result == expectedValue) { - this.value = newValue; - } - } - return result; + return compareAndExchange(expectedValue, newValue); } - /** - * [FUNCTION] AtomicReferenceAutomaton::compareAndExchangeRelease(LSLAtomicReference, Object, Object) -> Object - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:112 - */ public final Object compareAndExchangeRelease(Object expectedValue, Object newValue) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - if (result == expectedValue) { - this.value = newValue; - } - } - return result; + return compareAndExchange(expectedValue, newValue); } - /** - * [FUNCTION] AtomicReferenceAutomaton::compareAndSet(LSLAtomicReference, Object, Object) -> boolean - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:121 - */ public final boolean compareAndSet(Object expectedValue, Object newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value == expectedValue; - if (result) { - this.value = newValue; - } - } + boolean result = this.value == expectedValue; + if (result) + this.value = newValue; + return result; } - /** - * [FUNCTION] AtomicReferenceAutomaton::get(LSLAtomicReference) -> Object - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:129 - */ public final Object get() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - } - return result; + return this.value; } - /** - * [FUNCTION] AtomicReferenceAutomaton::getAcquire(LSLAtomicReference) -> Object - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:135 - */ public final Object getAcquire() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - } - return result; + return this.value; } - /** - * [FUNCTION] AtomicReferenceAutomaton::getAndAccumulate(LSLAtomicReference, Object, BinaryOperator) -> Object - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:142 - */ - public final Object getAndAccumulate(Object x, BinaryOperator accumulatorFunction) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - this.value = accumulatorFunction.apply(result, x); - } + public final Object getAndAccumulate(Object x, BinaryOperator accumulatorFunction) { + Object result = this.value; + this.value = accumulatorFunction.apply(result, x); + return result; } - /** - * [FUNCTION] AtomicReferenceAutomaton::getAndSet(LSLAtomicReference, Object) -> Object - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:149 - */ public final Object getAndSet(Object newValue) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - this.value = newValue; - } + Object result = this.value; + this.value = newValue; + return result; } - /** - * [FUNCTION] AtomicReferenceAutomaton::getAndUpdate(LSLAtomicReference, UnaryOperator) -> Object - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:156 - */ - public final Object getAndUpdate(UnaryOperator updateFunction) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - this.value = updateFunction.apply(result); - } + public final Object getAndUpdate(UnaryOperator updateFunction) { + Object result = this.value; + this.value = updateFunction.apply(result); + return result; } - /** - * [FUNCTION] AtomicReferenceAutomaton::getOpaque(LSLAtomicReference) -> Object - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:163 - */ public final Object getOpaque() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - } - return result; + return this.value; } - /** - * [FUNCTION] AtomicReferenceAutomaton::getPlain(LSLAtomicReference) -> Object - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:170 - */ public final Object getPlain() { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value; - } - return result; + return this.value; } - /** - * [FUNCTION] AtomicReferenceAutomaton::lazySet(LSLAtomicReference, Object) -> void - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:177 - */ - public final void lazySet(Object newValue) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.value = newValue; - } + public final void set(Object newValue) { + this.value = newValue; } - /** - * [FUNCTION] AtomicReferenceAutomaton::set(LSLAtomicReference, Object) -> void - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:184 - */ - public final void set(Object newValue) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.value = newValue; - } + public final void lazySet(Object newValue) { + this.value = newValue; } - /** - * [FUNCTION] AtomicReferenceAutomaton::setOpaque(LSLAtomicReference, Object) -> void - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:190 - */ public final void setOpaque(Object newValue) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.value = newValue; - } + this.value = newValue; } - /** - * [FUNCTION] AtomicReferenceAutomaton::setPlain(LSLAtomicReference, Object) -> void - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:197 - */ public final void setPlain(Object newValue) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.value = newValue; - } + this.value = newValue; } - /** - * [FUNCTION] AtomicReferenceAutomaton::setRelease(LSLAtomicReference, Object) -> void - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:204 - */ public final void setRelease(Object newValue) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.value = newValue; - } + this.value = newValue; } - /** - * [FUNCTION] AtomicReferenceAutomaton::toString(LSLAtomicReference) -> String - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:211 - */ public String toString() { - String result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = LibSLRuntime.toString(this.value); - } - return result; + return LibSLRuntime.toString(this.value); } - /** - * [FUNCTION] AtomicReferenceAutomaton::updateAndGet(LSLAtomicReference, UnaryOperator) -> Object - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:217 - */ - public final Object updateAndGet(UnaryOperator updateFunction) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = updateFunction.apply(this.value); - this.value = result; - } + public final Object updateAndGet(UnaryOperator updateFunction) { + Object result = updateFunction.apply(this.value); + this.value = result; + return result; } - /** - * [FUNCTION] AtomicReferenceAutomaton::weakCompareAndSet(LSLAtomicReference, Object, Object) -> boolean - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:224 - */ public final boolean weakCompareAndSet(Object expectedValue, Object newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value == expectedValue; - if (result) { - this.value = newValue; - } - } - return result; + return compareAndSet(expectedValue, newValue); } - /** - * [FUNCTION] AtomicReferenceAutomaton::weakCompareAndSetAcquire(LSLAtomicReference, Object, Object) -> boolean - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:233 - */ public final boolean weakCompareAndSetAcquire(Object expectedValue, Object newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value == expectedValue; - if (result) { - this.value = newValue; - } - } - return result; + return compareAndSet(expectedValue, newValue); } - /** - * [FUNCTION] AtomicReferenceAutomaton::weakCompareAndSetPlain(LSLAtomicReference, Object, Object) -> boolean - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:242 - */ public final boolean weakCompareAndSetPlain(Object expectedValue, Object newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value == expectedValue; - if (result) { - this.value = newValue; - } - } - return result; + return compareAndSet(expectedValue, newValue); } - /** - * [FUNCTION] AtomicReferenceAutomaton::weakCompareAndSetRelease(LSLAtomicReference, Object, Object) -> boolean - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:251 - */ public final boolean weakCompareAndSetRelease(Object expectedValue, Object newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value == expectedValue; - if (result) { - this.value = newValue; - } - } - return result; + return compareAndSet(expectedValue, newValue); } - /** - * [FUNCTION] AtomicReferenceAutomaton::weakCompareAndSetVolatile(LSLAtomicReference, Object, Object) -> boolean - * Source: java/util/concurrent/atomic/AtomicReference.main.lsl:260 - */ public final boolean weakCompareAndSetVolatile(Object expectedValue, Object newValue) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.value == expectedValue; - if (result) { - this.value = newValue; - } - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(AtomicReference.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } + return compareAndSet(expectedValue, newValue); } } diff --git a/approximations/src/main/java/generated/java/util/list/AbstractListImpl.java b/approximations/src/main/java/generated/java/util/list/AbstractListImpl.java new file mode 100644 index 00000000..814fc3f4 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/list/AbstractListImpl.java @@ -0,0 +1,577 @@ +package generated.java.util.list; + +import java.lang.Comparable; +import java.lang.IllegalArgumentException; +import java.lang.IndexOutOfBoundsException; +import java.lang.NullPointerException; +import java.lang.Object; +import java.lang.String; +import java.util.*; +import java.util.function.Consumer; +import java.util.function.IntFunction; +import java.util.function.Predicate; +import java.util.function.UnaryOperator; +import java.util.stream.Stream; + +import generated.java.util.AbstractCollectionImpl; +import generated.java.util.stream.StreamStubImpl; +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; +import org.usvm.api.SymbolicList; +import runtime.LibSLRuntime; + +@Approximate(java.util.AbstractList.class) +public abstract class AbstractListImpl extends AbstractCollectionImpl implements List { + + public SymbolicList storage; + + public AbstractListImpl(SymbolicList storage, int modCount) { + super(modCount); + this.storage = storage; + } + + public AbstractListImpl() { + this(Engine.makeSymbolicList(), 0); + } + + public AbstractListImpl(Collection c) { + super(0); + + if (c == null) + throw new NullPointerException(); + + this.storage = Engine.makeSymbolicList(); + _addAllElements(0, c); + } + + public AbstractListImpl(int initialCapacity) { + super(0); + + if (initialCapacity < 0) + throw new IllegalArgumentException(); + + this.storage = Engine.makeSymbolicList(); + } + + public SymbolicList _getStorage() { + SymbolicList storage = this.storage; + Engine.assume(storage != null); + return storage; + } + + public boolean _isValidIndex(int index, int length) { + return index >= 0 && index < length; + } + + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + public boolean _isValidIndex(int index) { + return _isValidIndex(index, _getStorage().size()); + } + + public void _checkValidIndex(int index, int length) { + if (!_isValidIndex(index, length)) + throw new IndexOutOfBoundsException(); + } + + public void _checkValidIndex(int index) { + _checkValidIndex(index, _getStorage().size()); + } + + public boolean _isValidAddIndex(int index) { + return index >= 0 && index <= _getStorage().size(); + } + + public void _checkValidAddIndex(int index) { + if (!_isValidAddIndex(index)) + throw new IndexOutOfBoundsException(); + } + + @SuppressWarnings({"DataFlowIssue", "unchecked"}) + public boolean _addAllElements(int index, Collection c) { + SymbolicList storage = _getStorage(); + int oldLength = storage.size(); + if (c instanceof AbstractListImpl) { + AbstractListImpl other = (AbstractListImpl) c; + SymbolicList otherStorage = other._getStorage(); + Engine.assume(otherStorage != null); + int otherLength = otherStorage.size(); + Engine.assume(otherLength >= 0); + otherStorage.copy(storage, 0, index, otherLength); + } else { + for (E item : c) { + storage.insert(index, item); + index++; + } + } + + this.modCount++; + return oldLength != storage.size(); + } + + public void _subListRangeCheck(int fromIndex, int toIndex, int size) { + if (fromIndex < 0) + throw new IndexOutOfBoundsException(); + + if (toIndex > size) + throw new IndexOutOfBoundsException(); + + if (fromIndex > toIndex) + throw new IllegalArgumentException(); + } + + public void _checkForModification(int expectedModCount) { + if (this.modCount != expectedModCount) + throw new ConcurrentModificationException(); + } + + public E _deleteElement(int index) { + SymbolicList storage = _getStorage(); + E result = storage.get(index); + storage.remove(index); + this.modCount++; + return result; + } + + public E _checkedDeleteElement(int index) { + _checkValidIndex(index); + return _deleteElement(index); + } + + public void _addElement(int index, E element) { + _getStorage().insert(index, element); + this.modCount++; + } + + public void _checkedAddElement(int index, E element) { + _checkValidAddIndex(index); + _addElement(index, element); + } + + public E _setElement(int index, E element) { + SymbolicList storage = _getStorage(); + E oldValue = storage.get(index); + storage.set(index, element); + return oldValue; + } + + public E _checkedSetElement(int index, E element) { + _checkValidIndex(index); + return _setElement(index, element); + } + + public E __get(int index) { + return _getStorage().get(index); + } + + public E _checkedGet(int index) { + _checkValidIndex(index); + return _getStorage().get(index); + } + + public void _replaceAllRange(UnaryOperator op, int i, int end) { + int expectedModCount = this.modCount; + SymbolicList storage = _getStorage(); + while (this.modCount == expectedModCount && i < end) { + E oldItem = storage.get(i); + E newItem = op.apply(oldItem); + storage.set(i, newItem); + i++; + } + _checkForModification(expectedModCount); + } + + public boolean _removeIf(Predicate filter, int start, int end) { + if (filter == null) + throw new NullPointerException(); + + SymbolicList storage = _getStorage(); + int oldLength = storage.size(); + int expectedModCount = this.modCount; + Engine.assume(start <= end); + for (int i = end - 1; i > start; i--) { + E item = storage.get(i); + if (filter.test(item)) + storage.remove(i); + } + + _checkForModification(expectedModCount); + return oldLength != storage.size(); + } + + public boolean _equalsStorage(SymbolicList otherStorage, int from, int to) { + SymbolicList storage = _getStorage(); + for (int i = from; i < to; i++) { + E a = otherStorage.get(i); + E b = storage.get(i); + if (!LibSLRuntime.equals(a, b)) + return false; + } + return true; + } + + public boolean _equalsRange(List other, int from, int to) { + if (other instanceof SubListImpl) { + SubListImpl otherSubList = (SubListImpl) other; + AbstractListImpl otherRoot = otherSubList.list; + SymbolicList otherStorage = otherRoot._getStorage(); + if (to != otherSubList.length) + return false; + + return _equalsStorage(otherStorage, from, to); + } + + if (other instanceof AbstractListImpl) { + AbstractListImpl otherList = (AbstractListImpl) other; + SymbolicList otherStorage = otherList._getStorage(); + if (to != otherStorage.size()) + return false; + + return _equalsStorage(otherStorage, from, to); + } + + SymbolicList storage = _getStorage(); + Iterator iter = other.iterator(); + boolean result = true; + int i = from; + while (result && i < to && iter.hasNext()) { + E a = iter.next(); + E b = storage.get(i); + result = LibSLRuntime.equals(a, b); + i++; + } + + return result && !iter.hasNext(); + } + + protected Object[] _mapToArray() { + SymbolicList storage = _getStorage(); + int count = storage.size(); + Object[] items = new Object[count]; + for (int i = 0; i < count; i++) { + items[i] = storage.get(i); + } + return items; + } + + @SuppressWarnings("unchecked") + private Stream _makeStream(boolean parallel) { + E[] items = (E[]) _mapToArray(); + return new StreamStubImpl<>(items, parallel); + } + + @SuppressWarnings({"ConstantValue", "unchecked"}) + public boolean _batchRemove(Collection c, boolean complement, int start, int end) { + if (c == null) + throw new NullPointerException(); + + SymbolicList storage = _getStorage(); + int oldLength = storage.size(); + if (oldLength == 0 || start >= end) + return false; + + int otherLength = c.size(); + if (otherLength == 0) { + if (!complement) + return false; + + this.storage = Engine.makeSymbolicList(); + this.modCount++; + return true; + } + + Engine.assume(otherLength > 0); + start--; + end--; + if (c instanceof List) { + SymbolicList otherStorage = ((AbstractListImpl) c)._getStorage(); + Engine.assume(otherStorage != null); + boolean changed = false; + for (int i = end; i > start; i--) { + Object item = storage.get(i); + int storageSize = storage.size(); + int index = LibSLRuntime.ListActions.find(otherStorage, item, 0, storageSize); + boolean notExists = index == -1; + if (notExists == complement) { + _checkedDeleteElement(i); + changed = true; + } + } + return changed; + } + + boolean changed = false; + for (int i = end; i > start; i--) { + Object item = storage.get(i); + if (c.contains(item) != complement) { + _checkedDeleteElement(i); + changed = true; + } + } + + return changed; + } + + @SuppressWarnings("unchecked") + public void _do_sort(int start, int end, Comparator c) { + if (start >= end) { + this.modCount++; + return; + } + SymbolicList storage = _getStorage(); + int expectedModCount = this.modCount; + Engine.assume(start >= 0); + Engine.assume(end > 0); + int outerLimit = end - 1; + for (int i = start; i < outerLimit; i++) { + int innerLimit = end - i - 1; + for (int j = start; j < innerLimit; j++) { + int idxB = j + 1; + E a = storage.get(j); + E b = storage.get(idxB); + if (c != null && c.compare(a, b) > 0 || c == null && ((Comparable) a).compareTo(b) > 0) { + storage.set(j, b); + storage.set(idxB, a); + } + } + } + _checkForModification(expectedModCount); + } + + public boolean _add(E e) { + SymbolicList storage = _getStorage(); + storage.insert(storage.size(), e); + this.modCount++; + return true; + } + + public void _add(int index, E element) { + _checkedAddElement(index, element); + } + + public boolean _addAll(@NotNull Collection c) { + return _addAllElements(_getStorage().size(), c); + } + + public boolean _addAll(int index, @NotNull Collection c) { + _checkValidAddIndex(index); + return _addAllElements(index, c); + } + + public void _clear() { + this.storage = Engine.makeSymbolicList(); + this.modCount++; + } + + @SuppressWarnings("unchecked") + public Object _clone() throws CloneNotSupportedException { + AbstractListImpl clonedList = (AbstractListImpl) super.clone(); + SymbolicList storageCopy = Engine.makeSymbolicList(); + SymbolicList storage = _getStorage(); + storage.copy(storageCopy, 0, 0, storage.size()); + clonedList.storage = storageCopy; + clonedList.modCount = 0; + return clonedList; + } + + public boolean _contains(Object o) { + return _indexOf(o) != -1; + } + + @SuppressWarnings({"DataFlowIssue", "unchecked"}) + public boolean _containsAll(@NotNull Collection c) { + if (c instanceof AbstractListImpl) { + SymbolicList otherStorage = ((AbstractListImpl) c)._getStorage(); + Engine.assume(otherStorage != null); + int otherLength = otherStorage.size(); + Engine.assume(otherLength >= 0); + boolean result = true; + int i = 0; + while (result && i < otherLength) { + E item = otherStorage.get(i); + result = _contains(item); + i++; + } + return result; + } + + for (Object o : c) { + if (!_contains(o)) + return false; + } + + return true; + } + + public void _ensureCapacity(int minCapacity) { + this.modCount++; + } + + @SuppressWarnings("unchecked") + public boolean _equals(Object other) { + if (other == this) + return true; + + if (other instanceof AbstractListImpl) { + AbstractListImpl otherList = (AbstractListImpl) other; + int expectedModCount = this.modCount; + int otherExpectedModCount = otherList.modCount; + SymbolicList otherStorage = otherList._getStorage(); + SymbolicList storage = _getStorage(); + int size = storage.size(); + int otherSize = otherStorage.size(); + boolean result = size == otherSize && LibSLRuntime.equals(storage, otherStorage); + otherList._checkForModification(otherExpectedModCount); + _checkForModification(expectedModCount); + return result; + } + + return false; + } + + public void _forEach(Consumer _action) { + if (_action == null) + throw new NullPointerException(); + + int expectedModCount = this.modCount; + int i = 0; + SymbolicList storage = _getStorage(); + while (this.modCount == expectedModCount && i < storage.size()) { + E item = storage.get(i); + _action.accept(item); + i++; + } + _checkForModification(expectedModCount); + } + + public E _get(int index) { + return _checkedGet(index); + } + + public int _hashCode() { + return LibSLRuntime.hashCode(_getStorage()); + } + + public int _indexOf(Object o) { + SymbolicList storage = _getStorage(); + return LibSLRuntime.ListActions.find(storage, o, 0, storage.size()); + } + + public boolean _isEmpty() { + return _getStorage().size() == 0; + } + + @NotNull + public Iterator _iterator() { + return new ListIteratorStubImpl<>(this); + } + + public int _lastIndexOf(Object o) { + SymbolicList storage = _getStorage(); + int size = storage.size(); + if (size == 0) + return -1; + + Engine.assume(size > 0); + for (int i = size - 1; i > -1; i--) { + E e = storage.get(i); + if (LibSLRuntime.equals(o, e)) { + return i; + } + } + return -1; + } + + @NotNull + public ListIterator _listIterator() { + return new ListIteratorStubImpl<>(this); + } + + @NotNull + public ListIterator _listIterator(int index) { + _checkValidAddIndex(index); + return new ListIteratorStubImpl<>(this, index); + } + + public Stream _parallelStream() { + return _makeStream(true); + } + + public boolean _remove(Object o) { + int index = _indexOf(o); + if (index == -1) + return false; + + _deleteElement(index); + return true; + + } + + public E _remove(int index) { + return _checkedDeleteElement(index); + } + + public boolean _removeAll(@NotNull Collection c) { + return _batchRemove(c, false, 0, _getStorage().size()); + } + + public boolean _removeIf(Predicate filter) { + return _removeIf(filter, 0, _getStorage().size()); + } + + public void _replaceAll(UnaryOperator op) { + if (op == null) + throw new NullPointerException(); + + _replaceAllRange(op, 0, _getStorage().size()); + this.modCount++; + } + + public boolean _retainAll(@NotNull Collection c) { + return _batchRemove(c, true, 0, _getStorage().size()); + } + + public E _set(int index, E element) { + return _checkedSetElement(index, element); + } + + public int _size() { + return _getStorage().size(); + } + + public void _sort(Comparator c) { + _do_sort(0, _getStorage().size(), c); + } + + public Spliterator _spliterator() { + return new ListSpliteratorStubImpl<>(this); + } + + public Stream _stream() { + return _makeStream(false); + } + + @NotNull + public List _subList(int fromIndex, int toIndex) { + _subListRangeCheck(fromIndex, toIndex, _getStorage().size()); + return new SubListImpl<>(this, fromIndex, toIndex); + } + + @NotNull + public Object[] _toArray() { + return _mapToArray(); + } + + public T[] _toArray(IntFunction generator) { + return super._toArray(generator); + } + + @NotNull + public T[] _toArray(@NotNull T[] array) { + return super.toArray(array); + } + + public String _toString() { + return LibSLRuntime.toString(_getStorage()); + } +} diff --git a/approximations/src/main/java/generated/java/util/list/ArrayListImpl.java b/approximations/src/main/java/generated/java/util/list/ArrayListImpl.java new file mode 100644 index 00000000..5b191795 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/list/ArrayListImpl.java @@ -0,0 +1,201 @@ +package generated.java.util.list; + +import java.io.Serial; +import java.io.Serializable; +import java.lang.Object; +import java.lang.String; +import java.util.*; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.IntFunction; +import java.util.function.Predicate; +import java.util.function.UnaryOperator; +import java.util.stream.Stream; + +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; +import org.usvm.api.SymbolicList; + +@SuppressWarnings("unused") +@Approximate(java.util.ArrayList.class) +public class ArrayListImpl extends AbstractListImpl implements RandomAccess, Cloneable, Serializable { + + @Serial + private static final long serialVersionUID = 8683452581122892189L; + + static { + Engine.assume(true); + } + + @SuppressWarnings("unused") + public ArrayListImpl(SymbolicList storage, int modCount) { + super(storage, modCount); + } + + @SuppressWarnings("unused") + public ArrayListImpl() { + super(); + } + + @SuppressWarnings("unused") + public ArrayListImpl(Collection c) { + super(c); + } + + @SuppressWarnings("unused") + public ArrayListImpl(int initialCapacity) { + super(initialCapacity); + } + + public boolean add(E e) { + return super._add(e); + } + + public void add(int index, E element) { + super._add(index, element); + } + + public boolean addAll(@NotNull Collection c) { + return super._addAll(c); + } + + public boolean addAll(int index, @NotNull Collection c) { + return super._addAll(index, c); + } + + public void clear() { + super._clear(); + } + + public Object clone() throws CloneNotSupportedException { + return super._clone(); + } + + public boolean contains(Object o) { + return super._contains(o); + } + + @SuppressWarnings("SlowListContainsAll") + public boolean containsAll(@NotNull Collection c) { + return super._containsAll(c); + } + + public void ensureCapacity(int minCapacity) { + super._ensureCapacity(minCapacity); + } + + public boolean equals(Object other) { + return super._equals(other); + } + + public void forEach(Consumer _action) { + super._forEach(_action); + } + + public E get(int index) { + return super._get(index); + } + + public int hashCode() { + return super._hashCode(); + } + + public int indexOf(Object o) { + return super._indexOf(o); + } + + public boolean isEmpty() { + return super._isEmpty(); + } + + @NotNull + public Iterator iterator() { + return super._iterator(); + } + + public int lastIndexOf(Object o) { + return super._lastIndexOf(o); + } + + @NotNull + public ListIterator listIterator() { + return super._listIterator(); + } + + @NotNull + public ListIterator listIterator(int index) { + return super._listIterator(index); + } + + public Stream parallelStream() { + return super._parallelStream(); + } + + public boolean remove(Object o) { + return super._remove(o); + } + + public E remove(int index) { + return super._remove(index); + } + + public boolean removeAll(@NotNull Collection c) { + return super._removeAll(c); + } + + public boolean removeIf(Predicate filter) { + return super._removeIf(filter); + } + + public void replaceAll(UnaryOperator op) { + super._replaceAll(op); + } + + public boolean retainAll(@NotNull Collection c) { + return super._retainAll(c); + } + + public E set(int index, E element) { + return super._set(index, element); + } + + public int size() { + return super._size(); + } + + public void sort(Comparator c) { + super._sort(c); + } + + public Spliterator spliterator() { + return super._spliterator(); + } + + public Stream stream() { + return super._stream(); + } + + @NotNull + public List subList(int fromIndex, int toIndex) { + return super._subList(fromIndex, toIndex); + } + + @NotNull + public Object[] toArray() { + return super._toArray(); + } + + public T[] toArray(IntFunction generator) { + return super._toArray(generator); + } + + @NotNull + public T[] toArray(@NotNull T[] array) { + return super._toArray(array); + } + + public String toString() { + return super._toString(); + } +} diff --git a/approximations/src/main/java/generated/java/util/list/LinkedListImpl.java b/approximations/src/main/java/generated/java/util/list/LinkedListImpl.java new file mode 100644 index 00000000..96b6025b --- /dev/null +++ b/approximations/src/main/java/generated/java/util/list/LinkedListImpl.java @@ -0,0 +1,342 @@ +package generated.java.util.list; + +import java.io.Serial; +import java.io.Serializable; +import java.lang.Object; +import java.lang.String; +import java.util.Collection; +import java.util.Comparator; +import java.util.Deque; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.NoSuchElementException; +import java.util.Spliterator; +import java.util.function.Consumer; +import java.util.function.IntFunction; +import java.util.function.Predicate; +import java.util.function.UnaryOperator; +import java.util.stream.Stream; + +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; +import org.usvm.api.SymbolicList; +import runtime.LibSLRuntime; + +@Approximate(java.util.LinkedList.class) +public class LinkedListImpl extends AbstractListImpl implements Deque, Cloneable, Serializable { + + @Serial + private static final long serialVersionUID = 876323262645176354L; + + static { + Engine.assume(true); + } + + @SuppressWarnings("unused") + public LinkedListImpl(SymbolicList storage, int modCount) { + super(storage, modCount); + } + + @SuppressWarnings("unused") + public LinkedListImpl() { + super(); + } + + @SuppressWarnings("unused") + public LinkedListImpl(Collection c) { + super(c); + } + + private E _unlinkFirst() { + if (!_isValidIndex(0)) + throw new NoSuchElementException(); + + return _deleteElement(0); + } + + private E _getFirstElement() { + if (!_isValidIndex(0)) + throw new NoSuchElementException(); + + return __get(0); + } + + public boolean add(E e) { + return super._add(e); + } + + public void add(int index, E element) { + super._add(index, element); + } + + public boolean addAll(@NotNull Collection c) { + return super._addAll(c); + } + + public boolean addAll(int index, @NotNull Collection c) { + return super._addAll(index, c); + } + + public void addFirst(E e) { + _addElement(0, e); + } + + public void addLast(E e) { + _addElement(_getStorage().size(), e); + } + + public void clear() { + super._clear(); + } + + public Object clone() throws CloneNotSupportedException { + return super._clone(); + } + + public boolean contains(Object o) { + return super._contains(o); + } + + @SuppressWarnings("SlowListContainsAll") + public boolean containsAll(@NotNull Collection c) { + return super._containsAll(c); + } + + @NotNull + public Iterator descendingIterator() { + return new LinkedList_DescendingIteratorImpl<>(this); + } + + public E element() { + return _getFirstElement(); + } + + public boolean equals(Object o) { + return super._equals(o); + } + + public void forEach(Consumer _action) { + super._forEach(_action); + } + + public E get(int index) { + return super._get(index); + } + + public E getFirst() { + return _getFirstElement(); + } + + public E getLast() { + return super._get(_getStorage().size() - 1); + } + + public int hashCode() { + return super._hashCode(); + } + + public int indexOf(Object o) { + return super._indexOf(o); + } + + public boolean isEmpty() { + return super._isEmpty(); + } + + @NotNull + public Iterator iterator() { + return super._iterator(); + } + + public int lastIndexOf(Object o) { + return super._lastIndexOf(o); + } + + @NotNull + public ListIterator listIterator() { + return super._listIterator(); + } + + @NotNull + public ListIterator listIterator(int index) { + return super._listIterator(index); + } + + public boolean offer(E e) { + return add(e); + } + + public boolean offerFirst(E e) { + addFirst(e); + return true; + } + + public boolean offerLast(E e) { + addLast(e); + return true; + } + + public Stream parallelStream() { + return super._parallelStream(); + } + + public E peek() { + if (isEmpty()) + return null; + + return __get(0); + } + + public E peekFirst() { + return peek(); + } + + public E peekLast() { + int size = _getStorage().size(); + if (size == 0) + return null; + + return __get(size - 1); + } + + public E poll() { + if (isEmpty()) + return null; + + return _deleteElement(0); + } + + public E pollFirst() { + return poll(); + } + + public E pollLast() { + int size = _getStorage().size(); + if (size == 0) + return null; + + return _deleteElement(size - 1); + } + + public E pop() { + return _unlinkFirst(); + } + + public void push(E e) { + _addElement(0, e); + } + + public E remove() { + return _unlinkFirst(); + } + + public boolean remove(Object o) { + return super._remove(o); + } + + public E remove(int index) { + return super._remove(index); + } + + public boolean removeAll(@NotNull Collection c) { + return super._removeAll(c); + } + + public E removeFirst() { + return remove(); + } + + public boolean removeFirstOccurrence(Object o) { + return remove(o); + } + + public boolean removeIf(Predicate filter) { + return super._removeIf(filter); + } + + public E removeLast() { + int size = _getStorage().size(); + if (size == 0) { + throw new NoSuchElementException(); + } + + return _deleteElement(size - 1); + } + + public boolean removeLastOccurrence(Object o) { + SymbolicList storage = _getStorage(); + int size = storage.size(); + if (size == 0) + return false; + + Engine.assume(size > 0); + int index; + for (index = size - 1; index >= 0; index--) { + Object item = storage.get(index); + if (LibSLRuntime.equals(item, o)) { + break; + } + } + + if (index != -1) { + storage.remove(index); + this.modCount++; + return true; + } + + return false; + } + + public void replaceAll(UnaryOperator op) { + super._replaceAll(op); + } + + public boolean retainAll(@NotNull Collection c) { + return super._retainAll(c); + } + + public E set(int index, E element) { + return super._set(index, element); + } + + public int size() { + return super._size(); + } + + public void sort(Comparator c) { + super._sort(c); + } + + public Spliterator spliterator() { + return super._spliterator(); + } + + public Stream stream() { + return super._stream(); + } + + @NotNull + public List subList(int fromIndex, int toIndex) { + return super._subList(fromIndex, toIndex); + } + + @NotNull + public Object[] toArray() { + return super._toArray(); + } + + public T[] toArray(IntFunction generator) { + return super._toArray(generator); + } + + @NotNull + public T[] toArray(@NotNull T[] a) { + return super._toArray(a); + } + + public String toString() { + return super._toString(); + } +} diff --git a/approximations/src/main/java/generated/java/util/list/LinkedList_DescendingIteratorImpl.java b/approximations/src/main/java/generated/java/util/list/LinkedList_DescendingIteratorImpl.java new file mode 100644 index 00000000..66776808 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/list/LinkedList_DescendingIteratorImpl.java @@ -0,0 +1,50 @@ +package generated.java.util.list; + +import java.lang.NullPointerException; +import java.util.function.Consumer; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.SymbolicList; +import stub.java.util.list.LinkedList_DescendingIterator; + +@Approximate(LinkedList_DescendingIterator.class) +public final class LinkedList_DescendingIteratorImpl extends ListIteratorStubImpl { + + public LinkedList_DescendingIteratorImpl(LinkedListImpl list) { + super(list, list._getStorage().size()); + } + + @SuppressWarnings("unused") + private boolean _isEmpty() { + return !super.hasPrevious(); + } + + public boolean hasNext() { + return super.hasPrevious(); + } + + public E next() { + return super.previous(); + } + + public void remove() { + super.remove(); + } + + public void forEachRemaining(Consumer userAction) { + if (userAction == null) + throw new NullPointerException(); + + _checkForModification(); + int i = this.cursor; + SymbolicList storage = _getList()._getStorage(); + while (i >= 0) { + E item = storage.get(i); + userAction.accept(item); + i--; + _checkForModification(); + } + this.cursor = i; + this.lastRet = i + 1; + } +} diff --git a/approximations/src/main/java/generated/java/util/list/ListImpl.java b/approximations/src/main/java/generated/java/util/list/ListImpl.java new file mode 100644 index 00000000..a14458ca --- /dev/null +++ b/approximations/src/main/java/generated/java/util/list/ListImpl.java @@ -0,0 +1,137 @@ +package generated.java.util.list; + +import java.util.Collection; +import java.util.List; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import org.usvm.api.SymbolicList; + +@SuppressWarnings("unused") +@Approximate(java.util.List.class) +public interface ListImpl extends Collection { + + static List copyOf(Collection coll) { + return new ArrayListImpl<>(coll); + } + + static List of() { + return new ArrayListImpl<>(); + } + + static List of(E element) { + SymbolicList data = Engine.makeSymbolicList(); + data.insert(0, element); + return new ArrayListImpl<>(data, 0); + } + + static List of(E element1, E element2) { + SymbolicList data = Engine.makeSymbolicList(); + data.insert(0, element1); + data.insert(1, element2); + return new ArrayListImpl<>(data, 0); + } + + static List of(E e1, E e2, E e3) { + SymbolicList data = Engine.makeSymbolicList(); + data.insert(0, e1); + data.insert(1, e2); + data.insert(2, e3); + return new ArrayListImpl<>(data, 0); + } + + static List of(E e1, E e2, E e3, E e4) { + SymbolicList data = Engine.makeSymbolicList(); + data.insert(0, e1); + data.insert(1, e2); + data.insert(2, e3); + data.insert(3, e4); + return new ArrayListImpl<>(data, 0); + } + + static List of(E e1, E e2, E e3, E e4, E e5) { + SymbolicList data = Engine.makeSymbolicList(); + data.insert(0, e1); + data.insert(1, e2); + data.insert(2, e3); + data.insert(3, e4); + data.insert(4, e5); + return new ArrayListImpl<>(data, 0); + } + + static List of(E e1, E e2, E e3, E e4, E e5, E e6) { + SymbolicList data = Engine.makeSymbolicList(); + data.insert(0, e1); + data.insert(1, e2); + data.insert(2, e3); + data.insert(3, e4); + data.insert(4, e5); + data.insert(5, e6); + return new ArrayListImpl<>(data, 0); + } + + static List of(E e1, E e2, E e3, E e4, E e5, E e6, E e7) { + SymbolicList data = Engine.makeSymbolicList(); + data.insert(0, e1); + data.insert(1, e2); + data.insert(2, e3); + data.insert(3, e4); + data.insert(4, e5); + data.insert(5, e6); + data.insert(6, e7); + return new ArrayListImpl<>(data, 0); + } + + static List of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8) { + SymbolicList data = Engine.makeSymbolicList(); + data.insert(0, e1); + data.insert(1, e2); + data.insert(2, e3); + data.insert(3, e4); + data.insert(4, e5); + data.insert(5, e6); + data.insert(6, e7); + data.insert(7, e8); + return new ArrayListImpl<>(data, 0); + } + + static List of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9) { + SymbolicList data = Engine.makeSymbolicList(); + data.insert(0, e1); + data.insert(1, e2); + data.insert(2, e3); + data.insert(3, e4); + data.insert(4, e5); + data.insert(5, e6); + data.insert(6, e7); + data.insert(7, e8); + data.insert(8, e9); + return new ArrayListImpl<>(data, 0); + } + + static List of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10) { + SymbolicList data = Engine.makeSymbolicList(); + data.insert(0, e1); + data.insert(1, e2); + data.insert(2, e3); + data.insert(3, e4); + data.insert(4, e5); + data.insert(5, e6); + data.insert(6, e7); + data.insert(7, e8); + data.insert(8, e9); + data.insert(9, e10); + return new ArrayListImpl<>(data, 0); + } + + @SuppressWarnings("ConstantValue") + static List of(E[] elements) { + SymbolicList data = Engine.makeSymbolicList(); + int size = elements.length; + Engine.assume(size >= 0); + for (int i = 0; i < size; i++) { + data.insert(i, elements[i]); + } + return new ArrayListImpl<>(data, 0); + } +} diff --git a/approximations/src/main/java/generated/java/util/list/ListIteratorStubImpl.java b/approximations/src/main/java/generated/java/util/list/ListIteratorStubImpl.java new file mode 100644 index 00000000..b97694fd --- /dev/null +++ b/approximations/src/main/java/generated/java/util/list/ListIteratorStubImpl.java @@ -0,0 +1,145 @@ +package generated.java.util.list; + +import java.lang.IllegalStateException; +import java.lang.NullPointerException; +import java.util.ListIterator; +import java.util.NoSuchElementException; +import java.util.function.Consumer; + +import generated.java.util.AbstractIteratorImpl; +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import org.usvm.api.SymbolicList; +import stub.java.util.list.ListIteratorStub; + +@Approximate(ListIteratorStub.class) +public class ListIteratorStubImpl extends AbstractIteratorImpl implements ListIterator { + + public AbstractListImpl list; + + public int cursor; + + public int lastRet; + + public ListIteratorStubImpl(AbstractListImpl list, int index, int expectedModCount) { + super(expectedModCount); + Engine.assume(list != null); + this.list = list; + Engine.assume(index >= 0); + this.cursor = index; + this.lastRet = -1; + } + + public ListIteratorStubImpl(AbstractListImpl list, int index) { + this(list, index, list.modCount); + } + + public ListIteratorStubImpl(AbstractListImpl list) { + this(list, 0); + } + + protected AbstractListImpl _getList() { + AbstractListImpl result = this.list; + Engine.assume(result != null); + return result; + } + + protected int _parentModCount() { + return _getList().modCount; + } + + protected int _getSize(SymbolicList storage) { + return storage.size(); + } + + public boolean hasPrevious() { + return this.cursor > 0; + } + + public int nextIndex() { + return this.cursor; + } + + public int previousIndex() { + return this.cursor - 1; + } + + protected boolean _hasNext(int size) { + return this.cursor < size; + } + + public boolean hasNext() { + return _hasNext(_getList()._getStorage().size()); + } + + public E next() { + _checkForModification(); + if (!hasNext()) + throw new NoSuchElementException(); + + int i = this.cursor; + this.cursor = i + 1; + this.lastRet = i; + return _getList()._getStorage().get(i); + } + + public E previous() { + _checkForModification(); + if (!hasPrevious()) + throw new NoSuchElementException(); + + this.cursor--; + this.lastRet = this.cursor; + return _getList()._getStorage().get(this.cursor); + } + + public void remove() { + if (this.lastRet < 0) + throw new IllegalStateException(); + + _checkForModification(); + AbstractListImpl list = _getList(); + SymbolicList storage = list._getStorage(); + list.modCount++; + storage.remove(this.lastRet); + this.cursor = this.lastRet; + this.lastRet = -1; + this.expectedModCount = list.modCount; + } + + public void set(E e) { + if (this.lastRet < 0) + throw new IllegalStateException(); + + _checkForModification(); + SymbolicList storage = _getList()._getStorage(); + storage.set(this.lastRet, e); + } + + public void add(E e) { + _checkForModification(); + AbstractListImpl list = _getList(); + SymbolicList storage = list._getStorage(); + list.modCount++; + storage.insert(this.cursor, e); + this.cursor++; + this.lastRet = -1; + this.expectedModCount = list.modCount; + } + + public void forEachRemaining(Consumer userAction) { + if (userAction == null) + throw new NullPointerException(); + + _checkForModification(); + SymbolicList storage = _getList()._getStorage(); + int size = _getSize(storage); + while (this.cursor < size) { + E item = storage.get(this.cursor); + userAction.accept(item); + this.lastRet = this.cursor; + this.cursor++; + _checkForModification(); + } + } +} diff --git a/approximations/src/main/java/generated/java/util/list/ListSpliteratorStubImpl.java b/approximations/src/main/java/generated/java/util/list/ListSpliteratorStubImpl.java new file mode 100644 index 00000000..0ee02268 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/list/ListSpliteratorStubImpl.java @@ -0,0 +1,92 @@ +package generated.java.util.list; + +import generated.java.util.AbstractSpliteratorImpl; +import generated.runtime.LibSLGlobals; +import java.lang.NullPointerException; +import java.util.function.Consumer; +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import org.usvm.api.SymbolicList; +import stub.java.util.list.ListSpliteratorStub; + +@Approximate(ListSpliteratorStub.class) +public class ListSpliteratorStubImpl extends AbstractSpliteratorImpl { + + public AbstractListImpl list; + + protected ListSpliteratorStubImpl(AbstractListImpl list, int index, int fence, int expectedModCount) { + super(index, fence, expectedModCount); + Engine.assume(list != null); + this.list = list; + } + + public ListSpliteratorStubImpl(AbstractListImpl list) { + this(list, 0, -1, 0); + } + + private AbstractListImpl _getList() { + AbstractListImpl result = this.list; + Engine.assume(result != null); + return result; + } + + protected ListSpliteratorStubImpl _create(int index, int fence) { + return new ListSpliteratorStubImpl<>(this.list, index, fence, this.expectedModCount); + } + + protected int _parentModCount() { + return _getList().modCount; + } + + protected int _storageSize() { + return _getList()._getStorage().size(); + } + + public int characteristics() { + return LibSLGlobals.SPLITERATOR_ORDERED | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED; + } + + public long estimateSize() { + return super.estimateSize(); + } + + public void forEachRemaining(Consumer _action) { + if (_action == null) + throw new NullPointerException(); + + SymbolicList storage = _getList()._getStorage(); + int fence = _getFence(); + for (int i = this.index; i < fence; i++) { + E item = storage.get(i); + _action.accept(item); + } + this.index = fence; + _checkForModification(); + } + + public long getExactSizeIfKnown() { + return super.getExactSizeIfKnown(); + } + + public boolean tryAdvance(Consumer _action) { + if (_action == null) + throw new NullPointerException(); + + int fence = _getFence(); + int current = this.index; + if (current >= fence) + return false; + + this.index = current + 1; + SymbolicList storage = _getList()._getStorage(); + E item = storage.get(current); + _action.accept(item); + _checkForModification(); + + return true; + } + + public ListSpliteratorStubImpl trySplit() { + return (ListSpliteratorStubImpl) super.trySplit(); + } +} diff --git a/approximations/src/main/java/generated/java/util/list/SubListImpl.java b/approximations/src/main/java/generated/java/util/list/SubListImpl.java new file mode 100644 index 00000000..1b9c2148 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/list/SubListImpl.java @@ -0,0 +1,462 @@ +package generated.java.util.list; + +import java.io.Serial; +import java.io.Serializable; +import java.lang.Object; +import java.lang.String; +import java.util.*; +import java.util.function.Consumer; +import java.util.function.IntFunction; +import java.util.function.Predicate; +import java.util.function.UnaryOperator; +import java.util.stream.Stream; + +import generated.java.util.stream.StreamStubImpl; +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; +import org.usvm.api.SymbolicList; +import runtime.LibSLRuntime; +import stub.java.util.list.SubList; + +@Approximate(SubList.class) +public final class SubListImpl extends AbstractListImpl implements RandomAccess, Cloneable, Serializable { + + @Serial + private static final long serialVersionUID = 8683452581122892189L; + + public transient AbstractListImpl list; + + public SubListImpl parentSubList; + + public int offset; + + public int length; + + public int modCount; + + @SuppressWarnings("DataFlowIssue") + private SubListImpl(AbstractListImpl list, SubListImpl parent, int offset, int length, int modCount) { + Engine.assume(list != null); + Engine.assume(offset >= 0); + Engine.assume(length >= 0); + Engine.assume(offset + length <= list._getStorage().size()); + this.list = list; + this.parentSubList = parent; + this.offset = offset; + this.length = length; + this.modCount = modCount; + } + + public SubListImpl(AbstractListImpl list, int fromIndex, int toIndex) { + this(list, null, fromIndex, toIndex - fromIndex, list.modCount); + } + + public AbstractListImpl _getList() { + AbstractListImpl result = this.list; + Engine.assume(result != null); + return result; + } + + private int _effectiveIndex(int index) { + return this.offset + index; + } + + public int _endIndex() { + return _effectiveIndex(this.length); + } + + public boolean _addAllElements(int index, Collection c) { + list._checkValidIndex(index, this.length); + int effectiveIndex = _effectiveIndex(index); + AbstractListImpl list = _getList(); + if (c.isEmpty()) + return false; + + list._checkForModification(this.modCount); + list._addAllElements(effectiveIndex, c); + _updateSizeAndModCount(c.size()); + + return true; + } + + public void _updateSizeAndModCount(int sizeChange) { + this.length += sizeChange; + AbstractListImpl list = _getList(); + this.modCount = list.modCount; + SubListImpl parentSubList = this.parentSubList; + while (parentSubList != null) { + parentSubList.length += sizeChange; + parentSubList.modCount = this.modCount; + parentSubList = parentSubList.parentSubList; + } + } + + private int _indexOfElement(AbstractListImpl list, Object o) { + return LibSLRuntime.ListActions.find(list._getStorage(), o, this.offset, _endIndex()); + } + + private int _indexOfElement(Object o) { + AbstractListImpl list = _getList(); + list._checkForModification(this.modCount); + int index = _indexOfElement(list, o); + if (index != -1) + return index - this.offset; + + return -1; + } + + protected Object[] _mapToArray() { + AbstractListImpl list = _getList(); + list._checkForModification(this.modCount); + SymbolicList storage = list._getStorage(); + Object[] items = new Object[this.length]; + int endIndex = _endIndex(); + for (int i = this.offset; i < endIndex; i++) { + items[i] = storage.get(i); + } + return items; + } + + @SuppressWarnings("unchecked") + private Stream _makeStream(boolean parallel) { + E[] items = (E[]) _mapToArray(); + return new StreamStubImpl<>(items, parallel); + } + + private boolean _batchRemove(Collection c, boolean complement) { + AbstractListImpl list = _getList(); + list._checkForModification(this.modCount); + if (isEmpty()) + return false; + + SymbolicList storage = list._getStorage(); + int oldRootLength = storage.size(); + if (list._batchRemove(c, complement, this.offset, _endIndex())) { + int newRootLength = storage.size(); + _updateSizeAndModCount(newRootLength - oldRootLength); + return true; + } + + return false; + } + + public void add(int index, E element) { + AbstractListImpl list = _getList(); + list._checkForModification(this.modCount); + int effectiveIndex = _effectiveIndex(index); + list._checkedAddElement(effectiveIndex, element); + _updateSizeAndModCount(1); + } + + public boolean add(E e) { + add(this.length, e); + return true; + } + + public boolean addAll(@NotNull Collection c) { + return _addAllElements(this.length, c); + } + + public boolean addAll(int index, @NotNull Collection c) { + return _addAllElements(index, c); + } + + public void clear() { + AbstractListImpl list = _getList(); + list._checkForModification(this.modCount); + int size = this.length; + if (size == 0) + return; + + Engine.assume(size > 0); + int end = this.offset - 1; + int start = end + size; + SymbolicList rootStorage = list._getStorage(); + for (int i = start; i > end; i--) { + rootStorage.remove(i); + } + list.modCount++; + _updateSizeAndModCount(-size); + } + + @SuppressWarnings("unchecked") + public Object clone() throws CloneNotSupportedException { + SubListImpl cloned = (SubListImpl) super._clone(); + cloned.list = (AbstractListImpl) this.list._clone(); + cloned.parentSubList = (SubListImpl) this.parentSubList.clone(); + cloned.modCount = 0; + return cloned; + } + + public boolean contains(Object o) { + return _indexOfElement(o) != -1; + } + + @SuppressWarnings({"unchecked"}) + public boolean containsAll(@NotNull Collection c) { + if (c.isEmpty()) + return true; + + AbstractListImpl list = _getList(); + SymbolicList rootStorage = list._getStorage(); + int start = this.offset; + int end = _endIndex(); + if (c instanceof SubListImpl) { + SubListImpl otherSubList = (SubListImpl) c; + AbstractListImpl otherRoot = otherSubList._getList(); + SymbolicList otherStorage = otherRoot._getStorage(); + int otherOffset = otherSubList.offset; + int otherEnd = otherOffset + otherSubList.length; + Engine.assume(otherOffset >= 0); + Engine.assume(otherEnd >= 0); + for (int i = otherOffset; i < otherEnd; i++) { + E item = otherStorage.get(i); + if (LibSLRuntime.ListActions.find(rootStorage, item, start, end) == -1) + return false; + } + + return true; + } + + for (Object item : c) { + if (LibSLRuntime.ListActions.find(rootStorage, item, start, end) == -1) + return false; + } + + return true; + } + + @SuppressWarnings({"unchecked", "EqualsWhichDoesntCheckParameterClass"}) + public boolean equals(Object o) { + if (o == this) + return true; + + if (o == null || !Engine.typeIs(o, SubListImpl.class)) + return false; + + SubListImpl other = (SubListImpl) o; + int otherLength = other.length; + Engine.assume(otherLength >= 0); + if (this.length != otherLength) + return false; + + AbstractListImpl list = _getList(); + boolean result = list._equalsRange(other, this.offset, _endIndex()); + list._checkForModification(this.modCount); + + return result; + } + + public void forEach(Consumer _action) { + if (isEmpty()) + return; + + Engine.assume(this.length > 0); + AbstractListImpl list = _getList(); + SymbolicList rootStorage = list._getStorage(); + int expectedModCount = list.modCount; + this.modCount = expectedModCount; + int end = _endIndex(); + list._checkForModification(expectedModCount); + for (int i = this.offset; i < end; i++) { + _action.accept(rootStorage.get(i)); + list._checkForModification(expectedModCount); + } + } + + public E get(int index) { + AbstractListImpl list = _getList(); + list._checkValidIndex(index, this.length); + list._checkForModification(this.modCount); + int effectiveIndex = _effectiveIndex(index); + return list._getStorage().get(effectiveIndex); + } + + public int hashCode() { + int result = 1; + if (isEmpty()) + return result; + + Engine.assume(this.length > 0); + AbstractListImpl list = _getList(); + SymbolicList rootStorage = list._getStorage(); + result = LibSLRuntime.hashCode(rootStorage, this.offset, _endIndex()); + list._checkForModification(this.modCount); + + return result; + } + + public int indexOf(Object o) { + return _indexOfElement(o); + } + + public boolean isEmpty() { + return this.length == 0; + } + + @NotNull + public Iterator iterator() { + return new SubListIteratorStubImpl<>(this); + } + + public int lastIndexOf(Object o) { + AbstractListImpl list = _getList(); + list._checkForModification(this.modCount); + if (isEmpty()) + return -1; + + Engine.assume(this.length > 0); + int end = _endIndex(); + SymbolicList rootStorage = list._getStorage(); + int result = LibSLRuntime.ListActions.findBack(rootStorage, o, this.offset, end); + if (result == -1) + return result; + + result -= this.offset; + return result; + } + + @NotNull + public ListIterator listIterator() { + return new SubListIteratorStubImpl<>(this); + } + + @NotNull + public ListIterator listIterator(int index) { + return new SubListIteratorStubImpl<>(this, index); + } + + public Stream parallelStream() { + return _makeStream(true); + } + + public boolean remove(Object o) { + AbstractListImpl list = _getList(); + int index = _indexOfElement(list, o); + if (index == -1) + return false; + + list._checkForModification(this.modCount); + list._checkedDeleteElement(index); + _updateSizeAndModCount(-1); + + return true; + } + + public E remove(int index) { + AbstractListImpl list = _getList(); + list._checkValidIndex(index, this.length); + list._checkForModification(this.modCount); + int effectiveIndex = _effectiveIndex(index); + E result = list._checkedDeleteElement(effectiveIndex); + _updateSizeAndModCount(-1); + + return result; + } + + public boolean removeAll(@NotNull Collection c) { + return _batchRemove(c, false); + } + + public boolean removeIf(Predicate filter) { + AbstractListImpl list = _getList(); + list._checkForModification(this.modCount); + if (isEmpty()) + return false; + + SymbolicList storage = list._getStorage(); + int oldRootLength = storage.size(); + if (list._removeIf(filter, this.offset, _endIndex())) { + int newRootLength = storage.size(); + _updateSizeAndModCount(newRootLength - oldRootLength); + return true; + } + + return false; + } + + public void replaceAll(UnaryOperator operator) { + if (operator == null) + throw new NullPointerException(); + + _getList()._replaceAllRange(operator, this.offset, _endIndex()); + } + + public boolean retainAll(@NotNull Collection c) { + return _batchRemove(c, true); + } + + public E set(int index, E element) { + AbstractListImpl list = _getList(); + list._checkValidIndex(index, this.length); + list._checkForModification(this.modCount); + SymbolicList parentStorage = list._getStorage(); + int effectiveIndex = _effectiveIndex(index); + E oldValue = parentStorage.get(effectiveIndex); + parentStorage.set(effectiveIndex, element); + + return oldValue; + } + + public int size() { + _getList()._checkForModification(this.modCount); + return this.length; + } + + public void sort(Comparator c) { + AbstractListImpl list = _getList(); + list._do_sort(this.offset, _endIndex(), c); + this.modCount = list.modCount; + } + + public Spliterator spliterator() { + return new SubListSpliteratorStubImpl<>(this); + } + + public Stream stream() { + return _makeStream(false); + } + + @NotNull + public List subList(int fromIndex, int toIndex) { + AbstractListImpl list = _getList(); + list._subListRangeCheck(fromIndex, toIndex, this.length); + + return new SubListImpl<>(list, this, _effectiveIndex(fromIndex), toIndex - fromIndex, this.modCount); + } + + @NotNull + public Object[] toArray() { + return super._toArray(); + } + + public T[] toArray(IntFunction generator) { + return super._toArray(generator); + } + + @NotNull + public T[] toArray(@NotNull T[] array) { + return super._toArray(array); + } + + public String toString() { + if (this.length == 0) + return "[]"; + + String result = "["; + AbstractListImpl list = _getList(); + SymbolicList rootStorage = list._getStorage(); + int end = _endIndex(); + int counter = this.length; + for (int i = this.offset; i < end; i++) { + E item = rootStorage.get(i); + result = result.concat(LibSLRuntime.toString(item)); + counter--; + if (counter != 0) + result = result.concat(", "); + } + + return result.concat("]"); + } +} diff --git a/approximations/src/main/java/generated/java/util/list/SubListIteratorStubImpl.java b/approximations/src/main/java/generated/java/util/list/SubListIteratorStubImpl.java new file mode 100644 index 00000000..c6dd1957 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/list/SubListIteratorStubImpl.java @@ -0,0 +1,96 @@ +package generated.java.util.list; + +import java.util.function.Consumer; + +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import org.usvm.api.SymbolicList; +import stub.java.util.list.SubListIteratorStub; + +@Approximate(SubListIteratorStub.class) +public final class SubListIteratorStubImpl extends ListIteratorStubImpl { + + private final SubListImpl subList; + + private final int startIndex; + + private int endIndex; + + public SubListIteratorStubImpl( + AbstractListImpl list, + SubListImpl subList, + int cursor, + int expectedModCount, + int offset, + int length + ) { + super(list, cursor + offset, expectedModCount); + Engine.assume(list != null); + Engine.assume(subList != null); + this.subList = subList; + this.startIndex = offset; + this.endIndex = offset + length; + } + + public SubListIteratorStubImpl(SubListImpl subList, int index) { + this(subList._getList(), subList, index, subList.modCount, subList.offset, subList.length); + } + + public SubListIteratorStubImpl(SubListImpl subList) { + this(subList, 0); + } + + protected int _getSize(SymbolicList storage) { + return endIndex; + } + + private SubListImpl _getSubList() { + SubListImpl subList = this.subList; + Engine.assume(subList != null); + return subList; + } + + public boolean hasPrevious() { + return this.cursor > startIndex; + } + + public int nextIndex() { + return cursor - startIndex; + } + + public int previousIndex() { + return cursor - 1 - startIndex; + } + + public boolean hasNext() { + return _hasNext(endIndex); + } + + public E next() { + return super.next(); + } + + public E previous() { + return super.previous(); + } + + public void remove() { + super.remove(); + _getSubList()._updateSizeAndModCount(-1); + this.endIndex--; + } + + public void set(E e) { + super.set(e); + } + + public void add(E e) { + super.add(e); + _getSubList()._updateSizeAndModCount(1); + this.endIndex++; + } + + public void forEachRemaining(Consumer userAction) { + super.forEachRemaining(userAction); + } +} diff --git a/approximations/src/main/java/generated/java/util/list/SubListSpliteratorStubImpl.java b/approximations/src/main/java/generated/java/util/list/SubListSpliteratorStubImpl.java new file mode 100644 index 00000000..602276cc --- /dev/null +++ b/approximations/src/main/java/generated/java/util/list/SubListSpliteratorStubImpl.java @@ -0,0 +1,66 @@ +package generated.java.util.list; + +import java.util.function.Consumer; +import org.jacodb.approximation.annotation.Approximate; +import stub.java.util.list.SubListSpliteratorStub; + +@Approximate(SubListSpliteratorStub.class) +public final class SubListSpliteratorStubImpl extends ListSpliteratorStubImpl { + + public SubListImpl subList; + + public SubListSpliteratorStubImpl( + AbstractListImpl list, + SubListImpl subList, + int index, + int fence, + int expectedModCount + ) { + super(list, subList.offset + index, fence, expectedModCount); + this.subList = subList; + } + + public SubListSpliteratorStubImpl(SubListImpl subList, int index) { + this(subList._getList(), subList, index, -1, 0); + } + + public SubListSpliteratorStubImpl(SubListImpl subList) { + this(subList, 0); + } + + protected SubListSpliteratorStubImpl _create(int index, int fence) { + return new SubListSpliteratorStubImpl<>(this.list, subList, index, fence, this.expectedModCount); + } + + protected int _parentModCount() { + return this.subList.modCount; + } + + protected int _storageSize() { + return subList._endIndex(); + } + + public int characteristics() { + return super.characteristics(); + } + + public long estimateSize() { + return super.estimateSize(); + } + + public void forEachRemaining(Consumer _action) { + super.forEachRemaining(_action); + } + + public long getExactSizeIfKnown() { + return super.getExactSizeIfKnown(); + } + + public boolean tryAdvance(Consumer _action) { + return super.tryAdvance(_action); + } + + public SubListSpliteratorStubImpl trySplit() { + return (SubListSpliteratorStubImpl) super.trySplit(); + } +} diff --git a/approximations/src/main/java/generated/java/util/map/AbstractMapImpl.java b/approximations/src/main/java/generated/java/util/map/AbstractMapImpl.java new file mode 100644 index 00000000..84b2f104 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/map/AbstractMapImpl.java @@ -0,0 +1,507 @@ +package generated.java.util.map; + +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +import java.util.*; +import java.util.function.BiConsumer; +import java.util.function.BiFunction; +import java.util.function.Function; + +@Approximate(java.util.AbstractMap.class) +public abstract class AbstractMapImpl implements Map { + + public LibSLRuntime.Map> storage; + + public transient int modCount; + + final boolean isHashMap; + + static LibSLRuntime.Map.Container> _createContainer(boolean isHashMap) { + if (isHashMap) + return new LibSLRuntime.HashMapContainer<>(); + + return new LibSLRuntime.IdentityMapContainer<>(); + } + + static LibSLRuntime.Map> _createStorage(boolean isHashMap) { + return new LibSLRuntime.Map<>(_createContainer(isHashMap)); + } + + public AbstractMapImpl(boolean isHashMap) { + this.storage = _createStorage(isHashMap); + this.modCount = 0; + this.isHashMap = isHashMap; + } + + public AbstractMapImpl() { + this(true); + } + + public AbstractMapImpl(boolean isHashMap, Map m) { + this(isHashMap); + _addAllElements(m); + } + + public AbstractMapImpl(boolean isHashMap, int initialCapacity) { + if (initialCapacity < 0) + throw new IllegalArgumentException(); + + this.storage = _createStorage(isHashMap); + this.modCount = 0; + this.isHashMap = isHashMap; + } + + public AbstractMapImpl(boolean isHashMap, int initialCapacity, float loadFactor) { + if (initialCapacity < 0) + throw new IllegalArgumentException(); + + if (loadFactor <= 0 || loadFactor != loadFactor) + throw new IllegalArgumentException(); + + this.storage = _createStorage(isHashMap); + this.modCount = 0; + this.isHashMap = isHashMap; + } + + public LibSLRuntime.Map> _getStorage() { + LibSLRuntime.Map> result = this.storage; + Engine.assume(result != null); + return result; + } + + @SuppressWarnings("unchecked") + private void _addAllElements(Map m) { + LibSLRuntime.Map> storage = _getStorage(); + if (m instanceof AbstractMapImpl) { + AbstractMapImpl other = (AbstractMapImpl) m; + LibSLRuntime.Map> otherStorage = other._getStorage(); + storage.union(otherStorage); + return; + } + + Set> entrySet = m.entrySet(); + for (Entry oEntry : entrySet) { + K key = oEntry.getKey(); + V value = oEntry.getValue(); + if (storage.hasKey(key)) { + Entry entry = storage.get(key); + entry.setValue(value); + } else { + Entry entry = new AbstractMap_EntryImpl<>(key, value); + storage.set(key, entry); + } + this.modCount++; + } + } + + public void _checkForModification(int expectedModCount) { + if (this.modCount != expectedModCount) + throw new ConcurrentModificationException(); + } + + public void _clear() { + this.modCount++; + this.storage = _createStorage(this.isHashMap); + } + + @SuppressWarnings("unchecked") + public Object _clone() throws CloneNotSupportedException { + AbstractMapImpl clonedMap = (AbstractMapImpl) super.clone(); + clonedMap.storage = _getStorage().duplicate(); + clonedMap.modCount = 0; + return clonedMap; + } + + private Map.Entry _getEntry(K key) { + LibSLRuntime.Map> storage = _getStorage(); + if (storage.hasKey(key)) + return storage.get(key); + + return null; + } + + private V _getEntryValueIfNotNull(Map.Entry entry, V defaultValue) { + if (entry != null) + return entry.getValue(); + + return defaultValue; + } + + private V _getEntryValueIfNotNull(Map.Entry entry) { + return _getEntryValueIfNotNull(entry, null); + } + + private void _update(K key, Map.Entry entry, V newValue) { + LibSLRuntime.Map> storage = _getStorage(); + if (newValue == null) { + storage.remove(key); + } else { + if (entry != null) { + entry.setValue(newValue); + } else { + entry = new AbstractMap_EntryImpl<>(key, newValue); + storage.set(key, entry); + } + } + } + + @SuppressWarnings("ConstantValue") + public V _compute(K key, @NotNull BiFunction remappingFunction) { + if (remappingFunction == null) + throw new NullPointerException(); + + Map.Entry entry = _getEntry(key); + V oldValue = _getEntryValueIfNotNull(entry); + + int expectedModCount = this.modCount; + V newValue = remappingFunction.apply(key, oldValue); + _checkForModification(expectedModCount); + _update(key, entry, newValue); + + return newValue; + } + + @SuppressWarnings("ConstantValue") + public V _computeIfAbsent(K key, @NotNull Function mappingFunction) { + if (mappingFunction == null) + throw new NullPointerException(); + + Map.Entry entry = _getEntry(key); + V oldValue = _getEntryValueIfNotNull(entry); + + if (oldValue != null) + return oldValue; + + int expectedModCount = this.modCount; + V newValue = mappingFunction.apply(key); + _checkForModification(expectedModCount); + _update(key, entry, newValue); + + return newValue; + } + + @SuppressWarnings("ConstantValue") + public V _computeIfPresent(K key, @NotNull BiFunction remappingFunction) { + if (remappingFunction == null) + throw new NullPointerException(); + + Map.Entry entry = _getEntry(key); + V oldValue = _getEntryValueIfNotNull(entry); + + if (oldValue == null) + return oldValue; + + int expectedModCount = this.modCount; + V newValue = remappingFunction.apply(key, oldValue); + _checkForModification(expectedModCount); + _update(key, entry, newValue); + + return newValue; + } + + @SuppressWarnings("unchecked") + public boolean _containsKey(Object key) { + LibSLRuntime.Map> storage = _getStorage(); + return storage.size() != 0 && storage.hasKey((K) key); + } + + public boolean _containsValue(Object value) { + LibSLRuntime.Map> storage = _getStorage(); + int storageSize = storage.size(); + if (storageSize == 0) + return false; + + LibSLRuntime.Map> unseen = storage.duplicate(); + while (storageSize != 0) { + K curKey = unseen.anyKey(); + Map.Entry entry = unseen.get(curKey); + V curValue = entry.getValue(); + if (LibSLRuntime.equals(curValue, value)) + return true; + + unseen.remove(curKey); + storageSize--; + } + + return false; + } + + @NotNull + public Set> _entrySet() { + return new Map_EntrySetImpl<>(this); + } + + public boolean _equals(Object other) { + return __equals(other); + } + + @SuppressWarnings({"unchecked", "ConstantValue"}) + boolean __equals(Object other) { + if (other == this) + return true; + + if (!(other instanceof Map)) + return false; + + Map m = (Map) other; + LibSLRuntime.Map> storage = _getStorage(); + int thisLength = storage.size(); + if (thisLength != m.size()) + return false; + + Engine.assume(thisLength >= 0); + try { + LibSLRuntime.Map> unseen = storage.duplicate(); + while (thisLength > 0) { + K key = unseen.anyKey(); + Map.Entry entry = unseen.get(key); + V value = entry.getValue(); + if (value == null && m.get(key) != null) + return false; + if (value == null && !m.containsKey(key)) + return false; + if (value != null && !LibSLRuntime.equals(value, m.get(key))) + return false; + + unseen.remove(key); + thisLength--; + } + } catch (ClassCastException | NullPointerException e) { + return false; + } + + return true; + } + + public void _forEach(BiConsumer userAction) { + if (userAction == null) + throw new NullPointerException(); + + LibSLRuntime.Map> storage = _getStorage(); + int storageSize = storage.size(); + if (storageSize == 0) + return; + + Engine.assume(storageSize > 0); + int expectedModCount = this.modCount; + LibSLRuntime.Map> unseen = storage.duplicate(); + for (int i = 0; i < storageSize; i++) { + K curKey = unseen.anyKey(); + Map.Entry entry = unseen.get(curKey); + V curValue = entry.getValue(); + userAction.accept(curKey, curValue); + unseen.remove(curKey); + } + _checkForModification(expectedModCount); + } + + @SuppressWarnings("unchecked") + public V _get(Object key) { + return _getEntryValueIfNotNull(_getEntry((K) key)); + } + + @SuppressWarnings("unchecked") + public V _getOrDefault(Object key, V defaultValue) { + return _getEntryValueIfNotNull(_getEntry((K) key), defaultValue); + } + + public int _hashCode() { + return LibSLRuntime.hashCode(_getStorage()); + } + + public boolean _isEmpty() { + return _getStorage().size() == 0; + } + + @NotNull + public Set _keySet() { + return new Map_KeySetImpl<>(this); + } + + @SuppressWarnings("ConstantValue") + public V _merge(K key, @NotNull V value, @NotNull BiFunction remappingFunction) { + if (value == null) + throw new NullPointerException(); + + if (remappingFunction == null) + throw new NullPointerException(); + + LibSLRuntime.Map> storage = _getStorage(); + if (storage.hasKey(key)) { + Map.Entry entry = storage.get(key); + V oldValue = entry.getValue(); + V result; + if (oldValue == null) { + result = value; + } else { + int expectedModCount = this.modCount; + result = remappingFunction.apply(oldValue, value); + _checkForModification(expectedModCount); + } + if (result == null) { + storage.remove(key); + } else { + entry.setValue(result); + } + return result; + } + + Map.Entry entry = new AbstractMap_EntryImpl<>(key, value); + storage.set(key, entry); + this.modCount++; + return value; + } + + public V _put(K key, V value) { + LibSLRuntime.Map> storage = _getStorage(); + if (storage.hasKey(key)) { + Map.Entry entry = storage.get(key); + V result = entry.getValue(); + entry.setValue(value); + return result; + } + + Map.Entry entry = new AbstractMap_EntryImpl<>(key, value); + storage.set(key, entry); + this.modCount++; + + return null; + } + + @SuppressWarnings("ConstantValue") + public void _putAll(@NotNull Map m) { + if (m == null) + throw new NullPointerException(); + + _addAllElements(m); + } + + public V _putIfAbsent(K key, V value) { + LibSLRuntime.Map> storage = _getStorage(); + if (storage.hasKey(key)) { + Map.Entry entry = storage.get(key); + return entry.getValue(); + } + + Map.Entry entry = new AbstractMap_EntryImpl<>(key, value); + storage.set(key, entry); + this.modCount++; + + return null; + } + + @SuppressWarnings("unchecked") + public V _remove(Object key) { + K typedKey = (K) key; + LibSLRuntime.Map> storage = _getStorage(); + if (storage.hasKey(typedKey)) { + Map.Entry entry = storage.get(typedKey); + V result = entry.getValue(); + storage.remove(typedKey); + this.modCount++; + return result; + } + + return null; + } + + @SuppressWarnings("unchecked") + public boolean _remove(Object key, Object value) { + K typedKey = (K) key; + LibSLRuntime.Map> storage = _getStorage(); + if (storage.hasKey(typedKey)) { + Map.Entry entry = storage.get(typedKey); + V curValue = entry.getValue(); + if (LibSLRuntime.equals(curValue, value)) { + storage.remove(typedKey); + this.modCount++; + return true; + } + } + + return false; + } + + public V _replace(K key, V value) { + LibSLRuntime.Map> storage = _getStorage(); + if (storage.hasKey(key)) { + Map.Entry entry = storage.get(key); + V result = entry.getValue(); + entry.setValue(value); + return result; + } + + return null; + } + + public boolean _replace(K key, V oldValue, V newValue) { + LibSLRuntime.Map> storage = _getStorage(); + if (storage.hasKey(key)) { + Map.Entry entry = storage.get(key); + V curValue = entry.getValue(); + if (LibSLRuntime.equals(curValue, oldValue)) { + entry.setValue(newValue); + return true; + } + } + + return false; + } + + public void _replaceAll(BiFunction function) { + if (function == null) + throw new NullPointerException(); + + LibSLRuntime.Map> storage = _getStorage(); + int size = storage.size(); + if (size == 0) + return; + + Engine.assume(size > 0); + int expectedModCount = this.modCount; + LibSLRuntime.Map> unseen = storage.duplicate(); + for (int i = 0; i < size; i++) { + K key = unseen.anyKey(); + Map.Entry entry = unseen.get(key); + entry.setValue(function.apply(key, entry.getValue())); + unseen.remove(key); + } + _checkForModification(expectedModCount); + } + + public int _size() { + return _getStorage().size(); + } + + public String _toString() { + LibSLRuntime.Map> storage = _getStorage(); + int size = storage.size(); + if (size == 0) + return "{}"; + + Engine.assume(size > 0); + String result = "{"; + LibSLRuntime.Map> unseen = storage.duplicate(); + Engine.assume(size > 0); + int lastIndex = size - 1; + for (int i = 0; i < size; i++) { + K key = unseen.anyKey(); + Map.Entry entry = unseen.get(key); + unseen.remove(key); + result = result.concat(LibSLRuntime.toString(entry)); + if (i != lastIndex) + result = result.concat(", "); + } + + return result.concat("}"); + } + + @NotNull + public Collection _values() { + return new Map_ValuesImpl<>(this); + } + +} diff --git a/approximations/src/main/java/generated/java/util/map/AbstractMap_EntryImpl.java b/approximations/src/main/java/generated/java/util/map/AbstractMap_EntryImpl.java new file mode 100644 index 00000000..74ca5686 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/map/AbstractMap_EntryImpl.java @@ -0,0 +1,66 @@ +package generated.java.util.map; + +import java.lang.Object; +import java.lang.String; +import java.util.Map; + +import org.jacodb.approximation.annotation.Approximate; +import runtime.LibSLRuntime; +import stub.java.util.map.AbstractMap_Entry; + +@Approximate(AbstractMap_Entry.class) +public class AbstractMap_EntryImpl implements Map.Entry { + + public K key; + + public V value; + + @SuppressWarnings("unused") + public AbstractMap_EntryImpl(Map.Entry entry) { + this.key = entry.getKey(); + this.value = entry.getValue(); + } + + @SuppressWarnings("unused") + public AbstractMap_EntryImpl(K key, V value) { + this.key = key; + this.value = value; + } + + @SuppressWarnings("unchecked") + public boolean equals(Object other) { + if (other == this) + return true; + + if (other instanceof Map.Entry) { + Map.Entry oEntry = ((Map.Entry) other); + Object otherKey = oEntry.getKey(); + Object otherValue = oEntry.getValue(); + return LibSLRuntime.equals(this.key, otherKey) && LibSLRuntime.equals(this.value, otherValue); + } + + return false; + } + + public K getKey() { + return this.key; + } + + public V getValue() { + return this.value; + } + + public int hashCode() { + return LibSLRuntime.hashCode(this.key) ^ LibSLRuntime.hashCode(this.value); + } + + public V setValue(V value) { + V oldValue = this.value; + this.value = value; + return oldValue; + } + + public String toString() { + return LibSLRuntime.toString(this.key).concat("=").concat(LibSLRuntime.toString(this.value)); + } +} diff --git a/approximations/src/main/java/generated/java/util/map/ConcurrentHashMapImpl.java b/approximations/src/main/java/generated/java/util/map/ConcurrentHashMapImpl.java new file mode 100644 index 00000000..288303b4 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/map/ConcurrentHashMapImpl.java @@ -0,0 +1,155 @@ +package generated.java.util.map; + +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; + +import java.io.Serial; +import java.io.Serializable; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.function.BiConsumer; +import java.util.function.BiFunction; +import java.util.function.Function; + +@Approximate(ConcurrentHashMap.class) +public class ConcurrentHashMapImpl extends AbstractMapImpl implements ConcurrentMap, Serializable { + + @Serial + private static final long serialVersionUID = 7249069246763182397L; + + static { + Engine.assume(true); + } + + @SuppressWarnings("unused") + public ConcurrentHashMapImpl() { + super(true); + } + + public ConcurrentHashMapImpl(Map m) { + super(true, m); + } + + @SuppressWarnings("unused") + public ConcurrentHashMapImpl(int initialCapacity) { + super(true, initialCapacity); + } + + @SuppressWarnings("unused") + public ConcurrentHashMapImpl(int initialCapacity, float loadFactor) { + super(true, initialCapacity, loadFactor); + } + + public void clear() { + super._clear(); + } + + public Object clone() throws CloneNotSupportedException { + return super._clone(); + } + + public V compute(K key, @NotNull BiFunction remappingFunction) { + return super._compute(key, remappingFunction); + } + + public V computeIfAbsent(K key, @NotNull Function mappingFunction) { + return super._computeIfAbsent(key, mappingFunction); + } + + public V computeIfPresent(K key, @NotNull BiFunction remappingFunction) { + return super._computeIfPresent(key, remappingFunction); + } + + public boolean containsKey(Object key) { + return super._containsKey(key); + } + + public boolean containsValue(Object value) { + return super._containsValue(value); + } + + @NotNull + public Set> entrySet() { + return super._entrySet(); + } + + public boolean equals(Object other) { + return Engine.typeIs(other, ConcurrentHashMapImpl.class) && super._equals(other); + } + + public void forEach(BiConsumer userAction) { + super._forEach(userAction); + } + + public V get(Object key) { + return super._get(key); + } + + public V getOrDefault(Object key, V defaultValue) { + return super._getOrDefault(key, defaultValue); + } + + public int hashCode() { + return super._hashCode(); + } + + public boolean isEmpty() { + return super._isEmpty(); + } + + @NotNull + public Set keySet() { + return super._keySet(); + } + + public V merge(K key, @NotNull V value, @NotNull BiFunction remappingFunction) { + return super._merge(key, value, remappingFunction); + } + + public V put(K key, V value) { + return super._put(key, value); + } + + public void putAll(@NotNull Map m) { + super._putAll(m); + } + + public V putIfAbsent(@NotNull K key, V value) { + return super._putIfAbsent(key, value); + } + + public V remove(Object key) { + return super._remove(key); + } + + public boolean remove(@NotNull Object key, Object value) { + return super._remove(key, value); + } + + public V replace(@NotNull K key, @NotNull V value) { + return super._replace(key, value); + } + + public boolean replace(@NotNull K key, @NotNull V oldValue, @NotNull V newValue) { + return super._replace(key, oldValue, newValue); + } + + public void replaceAll(BiFunction function) { + super._replaceAll(function); + } + + public int size() { + return super._size(); + } + + public String toString() { + return super._toString(); + } + + @NotNull + public Collection values() { + return super._values(); + } +} diff --git a/approximations/src/main/java/generated/java/util/map/ConcurrentReferenceHashMapImpl.java b/approximations/src/main/java/generated/java/util/map/ConcurrentReferenceHashMapImpl.java new file mode 100644 index 00000000..d2916524 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/map/ConcurrentReferenceHashMapImpl.java @@ -0,0 +1,130 @@ +package generated.java.util.map; + +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.springframework.lang.Nullable; +import org.springframework.util.ConcurrentReferenceHashMap; +import runtime.LibSLRuntime; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentMap; + +@SuppressWarnings("unused") +@Approximate(org.springframework.util.ConcurrentReferenceHashMap.class) +public class ConcurrentReferenceHashMapImpl extends AbstractMapImpl implements ConcurrentMap { + + public ConcurrentReferenceHashMapImpl() { + super(true); + } + + public ConcurrentReferenceHashMapImpl(int initialCapacity) { + super(true, initialCapacity); + } + + public ConcurrentReferenceHashMapImpl(int initialCapacity, float loadFactor) { + super(true, initialCapacity, loadFactor); + } + + public ConcurrentReferenceHashMapImpl(int initialCapacity, int concurrencyLevel) { + this(initialCapacity); + } + + public ConcurrentReferenceHashMapImpl(int initialCapacity, ConcurrentReferenceHashMap.ReferenceType referenceType) { + this(initialCapacity); + } + + public ConcurrentReferenceHashMapImpl(int initialCapacity, float loadFactor, int concurrencyLevel) { + this(initialCapacity, loadFactor); + } + + public ConcurrentReferenceHashMapImpl(int initialCapacity, float loadFactor, int concurrencyLevel, ConcurrentReferenceHashMap.ReferenceType referenceType) { + this(initialCapacity, loadFactor); + } + + @Nullable + public V get(@Nullable Object key) { + return super._get(key); + } + + @Nullable + public V getOrDefault(@Nullable Object key, @Nullable V defaultValue) { + return super._getOrDefault(key, defaultValue); + } + + public boolean containsKey(@Nullable Object key) { + return super._containsKey(key); + } + + @Override + public boolean containsValue(Object value) { + return false; + } + + @Nullable + public V put(@Nullable K key, @Nullable V value) { + return super._put(key, value); + } + + @Nullable + public V putIfAbsent(@Nullable K key, @Nullable V value) { + return super._putIfAbsent(key, value); + } + + @Nullable + public V remove(@Nullable Object key) { + return super._remove(key); + } + + @Override + public void putAll(@NotNull Map m) { + + } + + public boolean remove(@Nullable Object key, @Nullable final Object value) { + return super._remove(key, value); + } + + public boolean replace(@Nullable K key, @Nullable final V oldValue, @Nullable final V newValue) { + return super._replace(key, oldValue, newValue); + } + + @Nullable + public V replace(@Nullable K key, @Nullable final V value) { + return super._replace(key, value); + } + + public void clear() { + super._clear(); + } + + @NotNull + @Override + public Set keySet() { + return null; + } + + @NotNull + @Override + public Collection values() { + return null; + } + + public void purgeUnreferencedEntries() { + LibSLRuntime.not_implemented(); + } + + public int size() { + return super._size(); + } + + public boolean isEmpty() { + return super._isEmpty(); + } + + @NotNull + public Set> entrySet() { + return super._entrySet(); + } +} diff --git a/approximations/src/main/java/generated/java/util/map/HashMapImpl.java b/approximations/src/main/java/generated/java/util/map/HashMapImpl.java new file mode 100644 index 00000000..1ece9b0c --- /dev/null +++ b/approximations/src/main/java/generated/java/util/map/HashMapImpl.java @@ -0,0 +1,157 @@ +package generated.java.util.map; + +import java.io.Serial; +import java.io.Serializable; +import java.lang.Object; +import java.lang.String; +import java.util.Collection; +import java.util.Map; +import java.util.Set; +import java.util.function.BiConsumer; +import java.util.function.BiFunction; +import java.util.function.Function; + +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; + +@Approximate(java.util.HashMap.class) +public class HashMapImpl extends AbstractMapImpl implements Cloneable, Serializable { + + @Serial + private static final long serialVersionUID = 362498820763181265L; + + static { + Engine.assume(true); + } + + @SuppressWarnings("unused") + public HashMapImpl() { + super(true); + } + + public HashMapImpl(Map m) { + super(true, m); + } + + @SuppressWarnings("unused") + public HashMapImpl(int initialCapacity) { + super(true, initialCapacity); + } + + @SuppressWarnings("unused") + public HashMapImpl(int initialCapacity, float loadFactor) { + super(true, initialCapacity, loadFactor); + } + + public void clear() { + super._clear(); + } + + public Object clone() throws CloneNotSupportedException { + return super._clone(); + } + + public V compute(K key, @NotNull BiFunction remappingFunction) { + return super._compute(key, remappingFunction); + } + + public V computeIfAbsent(K key, @NotNull Function mappingFunction) { + return super._computeIfAbsent(key, mappingFunction); + } + + public V computeIfPresent(K key, @NotNull BiFunction remappingFunction) { + return super._computeIfPresent(key, remappingFunction); + } + + public boolean containsKey(Object key) { + return super._containsKey(key); + } + + public boolean containsValue(Object value) { + return super._containsValue(value); + } + + @NotNull + public Set> entrySet() { + return super._entrySet(); + } + + public boolean equals(Object other) { + return Engine.typeIs(other, HashMapImpl.class) && __equals(other); + } + + public void forEach(BiConsumer userAction) { + super._forEach(userAction); + } + + public V get(Object key) { + return super._get(key); + } + + public V getOrDefault(Object key, V defaultValue) { + return super._getOrDefault(key, defaultValue); + } + + public int hashCode() { + return super._hashCode(); + } + + public boolean isEmpty() { + return super._isEmpty(); + } + + @NotNull + public Set keySet() { + return super._keySet(); + } + + public V merge(K key, @NotNull V value, @NotNull BiFunction remappingFunction) { + return super._merge(key, value, remappingFunction); + } + + public V put(K key, V value) { + return super._put(key, value); + } + + public void putAll(@NotNull Map m) { + super._putAll(m); + } + + public V putIfAbsent(K key, V value) { + return super._putIfAbsent(key, value); + } + + public V remove(Object key) { + return super._remove(key); + } + + public boolean remove(Object key, Object value) { + return super._remove(key, value); + } + + public V replace(K key, V value) { + return super._replace(key, value); + } + + public boolean replace(K key, V oldValue, V newValue) { + return super._replace(key, oldValue, newValue); + } + + public void replaceAll(BiFunction function) { + super._replaceAll(function); + } + + public int size() { + return super._size(); + } + + public String toString() { + return super._toString(); + } + + @NotNull + public Collection values() { + return super._values(); + } +} diff --git a/approximations/src/main/java/generated/java/util/map/LinkedHashMapImpl.java b/approximations/src/main/java/generated/java/util/map/LinkedHashMapImpl.java new file mode 100644 index 00000000..d157f541 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/map/LinkedHashMapImpl.java @@ -0,0 +1,157 @@ +package generated.java.util.map; + +import java.io.Serial; +import java.lang.Object; +import java.lang.String; +import java.lang.SuppressWarnings; +import java.util.Collection; +import java.util.Map; +import java.util.Set; +import java.util.function.BiConsumer; +import java.util.function.BiFunction; +import java.util.function.Function; +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; + +@Approximate(java.util.LinkedHashMap.class) +public class LinkedHashMapImpl extends HashMapImpl { + + @Serial + private static final long serialVersionUID = 3801124242820219131L; + + static { + Engine.assume(true); + } + + @SuppressWarnings("unused") + public LinkedHashMapImpl() { + super(); + } + + @SuppressWarnings("unused") + public LinkedHashMapImpl(Map m) { + super(m); + } + + @SuppressWarnings("unused") + public LinkedHashMapImpl(int initialCapacity) { + super(initialCapacity); + } + + @SuppressWarnings("unused") + public LinkedHashMapImpl(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + public void clear() { + super.clear(); + } + + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public V compute(K key, @NotNull BiFunction remappingFunction) { + return super.compute(key, remappingFunction); + } + + public V computeIfAbsent(K key, @NotNull Function mappingFunction) { + return super.computeIfAbsent(key, mappingFunction); + } + + public V computeIfPresent(K key, @NotNull BiFunction remappingFunction) { + return super.computeIfPresent(key, remappingFunction); + } + + public boolean containsKey(Object key) { + return super.containsKey(key); + } + + public boolean containsValue(Object value) { + return super.containsValue(value); + } + + @NotNull + public Set> entrySet() { + return super.entrySet(); + } + + public boolean equals(Object other) { + return Engine.typeIs(other, LinkedHashMapImpl.class) && __equals(other); + } + + public void forEach(BiConsumer userAction) { + super.forEach(userAction); + } + + public V get(Object key) { + return super.get(key); + } + + public V getOrDefault(Object key, V defaultValue) { + return super.getOrDefault(key, defaultValue); + } + + public int hashCode() { + return super.hashCode(); + } + + public boolean isEmpty() { + return super.isEmpty(); + } + + @NotNull + public Set keySet() { + return super.keySet(); + } + + public V merge(K key, @NotNull V value, @NotNull BiFunction remappingFunction) { + return super.merge(key, value, remappingFunction); + } + + public V put(K key, V value) { + return super.put(key, value); + } + + public void putAll(@NotNull Map m) { + super.putAll(m); + } + + public V putIfAbsent(K key, V value) { + return super.putIfAbsent(key, value); + } + + public V remove(Object key) { + return super.remove(key); + } + + public boolean remove(Object key, Object value) { + return super.remove(key, value); + } + + public V replace(K key, V value) { + return super.replace(key, value); + } + + public boolean replace(K key, V oldValue, V newValue) { + return super.replace(key, oldValue, newValue); + } + + public void replaceAll(BiFunction function) { + super.replaceAll(function); + } + + public int size() { + return super.size(); + } + + public String toString() { + return super.toString(); + } + + @NotNull + public Collection values() { + return super.values(); + } +} diff --git a/approximations/src/main/java/generated/java/util/map/Map_ContentsImpl.java b/approximations/src/main/java/generated/java/util/map/Map_ContentsImpl.java new file mode 100644 index 00000000..996bdd94 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/map/Map_ContentsImpl.java @@ -0,0 +1,275 @@ +package generated.java.util.map; + +import generated.java.util.AbstractCollectionImpl; +import generated.java.util.stream.StreamStubImpl; +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; +import stub.java.util.map.Map_Contents; + +import java.util.*; +import java.util.function.Consumer; +import java.util.function.IntFunction; +import java.util.function.Predicate; +import java.util.stream.Stream; + +@Approximate(Map_Contents.class) +public abstract class Map_ContentsImpl extends AbstractCollectionImpl { + + public AbstractMapImpl map; + + public Map_ContentsImpl(AbstractMapImpl map) { + super(0); + this.map = map; + } + + @SuppressWarnings("DataFlowIssue") + LibSLRuntime.Map> _getStorage() { + Engine.assume(this.map != null); + return this.map._getStorage(); + } + + abstract Content _contentByKey(LibSLRuntime.Map> storage, K key); + + @SuppressWarnings("ConstantValue") + protected Object[] _mapToArray() { + LibSLRuntime.Map> storage = _getStorage(); + int storageSize = storage.size(); + Object[] result = new Object[storageSize]; + if (storageSize == 0) + return result; + + Engine.assume(storageSize > 0); + LibSLRuntime.Map> unseen = storage.duplicate(); + for (int i = 0; i < storageSize; i++) { + K curKey = unseen.anyKey(); + result[i] = _contentByKey(storage, curKey); + unseen.remove(curKey); + } + return result; + } + + public boolean _add(Content e) { + throw new UnsupportedOperationException(); + } + + public boolean _addAll(@NotNull Collection c) { + throw new UnsupportedOperationException(); + } + + public void _clear() { + this.map._clear(); + } + + abstract boolean _containsInStorage(LibSLRuntime.Map> storage, Object o); + + public boolean _contains(Object obj) { + LibSLRuntime.Map> storage = _getStorage(); + if (storage.size() == 0) + return false; + + return _containsInStorage(storage, obj); + } + + public boolean _containsAll(@NotNull Collection c) { + if (c == this || c.isEmpty()) + return true; + + for (Object elem : c) { + if (!_contains(elem)) + return false; + } + + return true; + } + + Collection _equalsTypeCheck(Object other) { + if (other instanceof Collection) + return (Collection) other; + + return null; + } + + @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") + public boolean _equals(Object other) { + if (other == this) + return true; + + Collection c = _equalsTypeCheck(other); + if (c == null) + return false; + + if (_getStorage().size() != c.size()) + return false; + + return _containsAll(c); + } + + public void _forEach(Consumer userAction) { + if (userAction == null) + throw new NullPointerException(); + + LibSLRuntime.Map> storage = _getStorage(); + int size = storage.size(); + if (size == 0) + return; + + Engine.assume(size > 0); + int expectedModCount = this.map.modCount; + LibSLRuntime.Map> unseen = storage.duplicate(); + for (int i = 0; i < size; i++) { + K key = unseen.anyKey(); + userAction.accept(_contentByKey(storage, key)); + unseen.remove(key); + } + this.map._checkForModification(expectedModCount); + } + + public int _hashCode() { + return LibSLRuntime.hashCode(_getStorage()); + } + + public boolean _isEmpty() { + return _getStorage().size() == 0; + } + + @NotNull + public Iterator _iterator() { + return new Map_Contents_IteratorImpl<>(this, _getStorage().duplicate(), this.map.modCount); + } + + @SuppressWarnings("unchecked") + public Stream _parallelStream() { + Content[] items = (Content[]) _mapToArray(); + return new StreamStubImpl<>(items, true); + } + + public abstract boolean remove(Object o); + + @SuppressWarnings("ConstantValue") + public boolean _removeAll(@NotNull Collection c) { + if (c == null) + throw new NullPointerException(); + + LibSLRuntime.Map> storage = _getStorage(); + int startStorageSize = storage.size(); + int cSize = c.size(); + if (startStorageSize == 0 || cSize == 0) + return false; + + if (startStorageSize <= cSize) { + LibSLRuntime.Map> unseen = storage.duplicate(); + for (int i = 0; i < startStorageSize; i++) { + K key = unseen.anyKey(); + if (c.contains(_contentByKey(storage, key))) { + storage.remove(key); + this.map.modCount++; + } + unseen.remove(key); + } + + return startStorageSize != storage.size(); + } + + for (Object key : c) { + remove(key); + } + + return startStorageSize != storage.size(); + } + + public boolean _removeIf(Predicate filter) { + if (filter == null) + throw new NullPointerException(); + + LibSLRuntime.Map> storage = _getStorage(); + int startStorageSize = storage.size(); + if (startStorageSize == 0) + return false; + + LibSLRuntime.Map> unseen = storage.duplicate(); + for (int i = 0; i < startStorageSize; i++) { + K curKey = unseen.anyKey(); + if (filter.test(_contentByKey(storage, curKey))) { + storage.remove(curKey); + this.map.modCount++; + } + unseen.remove(curKey); + } + + return startStorageSize != storage.size(); + } + + @SuppressWarnings("ConstantValue") + public boolean _retainAll(@NotNull Collection c) { + if (c == null) + throw new NullPointerException(); + + LibSLRuntime.Map> storage = _getStorage(); + int startStorageSize = storage.size(); + int cSize = c.size(); + if (startStorageSize == 0 || cSize == 0) + return false; + + LibSLRuntime.Map> unseen = storage.duplicate(); + for (int i = 0; i < startStorageSize; i++) { + K curKey = unseen.anyKey(); + if (!c.contains(_contentByKey(storage, curKey))) { + storage.remove(curKey); + this.map.modCount++; + } + } + + return startStorageSize != storage.size(); + } + + public int _size() { + return this.map._size(); + } + + public Spliterator _spliterator() { + return new Map_Contents_SpliteratorImpl<>(this); + } + + @SuppressWarnings("unchecked") + public Stream _stream() { + Content[] items = (Content[]) _mapToArray(); + return new StreamStubImpl<>(items); + } + + @NotNull + public Object[] _toArray() { + return super._toArray(); + } + + public T[] _toArray(IntFunction generator) { + return super._toArray(generator); + } + + @NotNull + public T[] _toArray(@NotNull T[] array) { + return super.toArray(array); + } + + public String _toString() { + LibSLRuntime.Map> storage = _getStorage(); + int size = storage.size(); + if (size == 0) + return "[]"; + + String result = "["; + LibSLRuntime.Map> unseen = storage.duplicate(); + Engine.assume(size > 0); + int lastIndex = size - 1; + for (int i = 0; i < size; i++) { + K key = unseen.anyKey(); + unseen.remove(key); + result = result.concat(LibSLRuntime.toString(_contentByKey(storage, key))); + if (i != lastIndex) + result = result.concat(", "); + } + + return result.concat("]"); + } +} diff --git a/approximations/src/main/java/generated/java/util/map/Map_ContentsSetImpl.java b/approximations/src/main/java/generated/java/util/map/Map_ContentsSetImpl.java new file mode 100644 index 00000000..558457a5 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/map/Map_ContentsSetImpl.java @@ -0,0 +1,113 @@ +package generated.java.util.map; + +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import stub.java.util.map.Map_ContentsSet; + +import java.util.*; +import java.util.function.Consumer; +import java.util.function.IntFunction; +import java.util.function.Predicate; +import java.util.stream.Stream; + +@Approximate(Map_ContentsSet.class) +public abstract class Map_ContentsSetImpl extends Map_ContentsImpl implements Set { + + public Map_ContentsSetImpl(AbstractMapImpl map) { + super(map); + } + + public boolean _add(Content e) { + return super._add(e); + } + + public boolean _addAll(@NotNull Collection c) { + return super._addAll(c); + } + + public void _clear() { + super._clear(); + } + + public boolean _contains(Object obj) { + return super._contains(obj); + } + + public boolean _containsAll(@NotNull Collection c) { + return super._containsAll(c); + } + + Set _equalsTypeCheck(Object other) { + if (other instanceof Set) + return (Set) other; + + return null; + } + + public boolean _equals(Object other) { + return super._equals(other); + } + + public void _forEach(Consumer userAction) { + super._forEach(userAction); + } + + public int _hashCode() { + return super._hashCode(); + } + + public boolean _isEmpty() { + return super._isEmpty(); + } + + @NotNull + public Iterator _iterator() { + return super._iterator(); + } + + public Stream _parallelStream() { + return super._parallelStream(); + } + + public boolean _removeAll(@NotNull Collection c) { + return super._removeAll(c); + } + + public boolean _removeIf(Predicate filter) { + return super._removeIf(filter); + } + + public boolean _retainAll(@NotNull Collection c) { + return super._retainAll(c); + } + + public int _size() { + return super._size(); + } + + public Spliterator _spliterator() { + return new Map_ContentsSet_SpliteratorImpl<>(this); + } + + public Stream _stream() { + return super._stream(); + } + + @NotNull + public Object[] _toArray() { + return super._toArray(); + } + + public T[] _toArray(IntFunction generator) { + return super._toArray(generator); + } + + @NotNull + public T[] _toArray(@NotNull T[] array) { + return super._toArray(array); + } + + public String _toString() { + return super._toString(); + } +} diff --git a/approximations/src/main/java/generated/java/util/map/Map_ContentsSet_SpliteratorImpl.java b/approximations/src/main/java/generated/java/util/map/Map_ContentsSet_SpliteratorImpl.java new file mode 100644 index 00000000..e26bc6b6 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/map/Map_ContentsSet_SpliteratorImpl.java @@ -0,0 +1,66 @@ +package generated.java.util.map; + +import generated.runtime.LibSLGlobals; +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.SymbolicList; +import stub.java.util.map.Map_ContentsSet_Spliterator; + +import java.util.function.Consumer; + +@Approximate(Map_ContentsSet_Spliterator.class) +public class Map_ContentsSet_SpliteratorImpl extends Map_Contents_SpliteratorImpl { + + Map_ContentsSet_SpliteratorImpl( + Map_ContentsSetImpl set, + SymbolicList seenKeys, + SymbolicList unseenKeys, + int index, + int fence, + int expectedModCount + ) { + super(set, seenKeys, unseenKeys, index, fence, expectedModCount); + } + + public Map_ContentsSet_SpliteratorImpl(Map_ContentsSetImpl set) { + super(set); + } + + Map_ContentsSet_SpliteratorImpl _createSpliterator( + SymbolicList seenKeys, + SymbolicList unseenKeys, + int index, + int fence, + int expectedModCount + ) { + Map_ContentsSetImpl typedContents = (Map_ContentsSetImpl) this.contents; + return new Map_ContentsSet_SpliteratorImpl<>(typedContents, seenKeys, unseenKeys, index, fence, expectedModCount); + } + + protected int _defaultCharacteristics() { + return LibSLGlobals.SPLITERATOR_DISTINCT; + } + + public int characteristics() { + return super.characteristics(); + } + + public long estimateSize() { + return super.estimateSize(); + } + + public void forEachRemaining(Consumer userAction) { + super.forEachRemaining(userAction); + } + + public long getExactSizeIfKnown() { + return super.getExactSizeIfKnown(); + } + + public boolean tryAdvance(Consumer userAction) { + return super.tryAdvance(userAction); + } + + public Map_ContentsSet_SpliteratorImpl trySplit() { + return (Map_ContentsSet_SpliteratorImpl) super.trySplit(); + } +} diff --git a/approximations/src/main/java/generated/java/util/map/Map_Contents_IteratorImpl.java b/approximations/src/main/java/generated/java/util/map/Map_Contents_IteratorImpl.java new file mode 100644 index 00000000..76be1eca --- /dev/null +++ b/approximations/src/main/java/generated/java/util/map/Map_Contents_IteratorImpl.java @@ -0,0 +1,100 @@ +package generated.java.util.map; + +import generated.java.util.AbstractIteratorImpl; +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; +import stub.java.util.map.Map_Contents_Iterator; + +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.function.Consumer; + +@Approximate(Map_Contents_Iterator.class) +public class Map_Contents_IteratorImpl extends AbstractIteratorImpl { + + public Map_ContentsImpl contents; + + public LibSLRuntime.Map> unseen; + + public K currentKey; + + public Map_Contents_IteratorImpl( + Map_ContentsImpl contents, + LibSLRuntime.Map> unseen, + int expectedModCount + ) { + super(expectedModCount); + this.contents = contents; + this.unseen = unseen; + this.currentKey = null; + } + + private Map_ContentsImpl _getContents() { + Map_ContentsImpl result = this.contents; + Engine.assume(result != null); + return result; + } + + private AbstractMapImpl _getMap() { + AbstractMapImpl result = _getContents().map; + Engine.assume(result != null); + return result; + } + + protected int _parentModCount() { + return _getMap().modCount; + } + + private boolean _isEmpty() { + // TODO: make via 'contains(unseen.anyKey) == false' + return this.unseen.size() == 0; + } + + public void forEachRemaining(Consumer userAction) { + if (userAction == null) + throw new NullPointerException(); + + int size = this.unseen.size(); + Engine.assume(size >= 0); + Map_ContentsImpl contents = _getContents(); + while (size > 0) { + _checkForModification(); + K curKey = this.unseen.anyKey(); + userAction.accept(contents._contentByKey(this.unseen, curKey)); + this.unseen.remove(curKey); + size--; + } + } + + public boolean hasNext() { + return !_isEmpty(); + } + + public Content next() { + _checkForModification(); + if (_isEmpty()) + throw new NoSuchElementException(); + + K curKey = this.unseen.anyKey(); + Map_ContentsImpl contents = _getContents(); + Content result = contents._contentByKey(this.unseen, curKey); + this.unseen.remove(curKey); + this.currentKey = curKey; + return result; + } + + public void remove() { + K key = this.currentKey; + if (key == null) + throw new IllegalStateException(); + + _checkForModification(); + AbstractMapImpl map = _getMap(); + map._getStorage().remove(key); + map.modCount++; + this.unseen.remove(key); + this.expectedModCount = map.modCount; + this.currentKey = null; + } +} diff --git a/approximations/src/main/java/generated/java/util/map/Map_Contents_SpliteratorImpl.java b/approximations/src/main/java/generated/java/util/map/Map_Contents_SpliteratorImpl.java new file mode 100644 index 00000000..d3a388d0 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/map/Map_Contents_SpliteratorImpl.java @@ -0,0 +1,203 @@ +package generated.java.util.map; + +import generated.java.util.AbstractSpliteratorImpl; +import generated.runtime.LibSLGlobals; +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import org.usvm.api.SymbolicList; +import runtime.LibSLRuntime; +import stub.java.util.map.Map_Contents_Spliterator; + +import java.util.Map; +import java.util.function.Consumer; + +import static runtime.LibSLRuntime.error; + +@Approximate(Map_Contents_Spliterator.class) +public class Map_Contents_SpliteratorImpl extends AbstractSpliteratorImpl { + + Map_ContentsImpl contents; + + SymbolicList seenKeys; + + SymbolicList unseenKeys; + + Map_Contents_SpliteratorImpl( + Map_ContentsImpl contents, + SymbolicList seenKeys, + SymbolicList unseenKeys, + int index, + int fence, + int expectedModCount + ) { + super(index, fence, expectedModCount); + this.contents = contents; + this.seenKeys = seenKeys; + this.unseenKeys = unseenKeys; + } + + public Map_Contents_SpliteratorImpl(Map_ContentsImpl contents) { + this(contents, Engine.makeSymbolicList(), null, 0, -1, 0); + } + + protected AbstractSpliteratorImpl _create(int index, int fence) { + return null; + } + + Map_Contents_SpliteratorImpl _createSpliterator( + SymbolicList seenKeys, + SymbolicList unseenKeys, + int index, + int fence, + int expectedModCount + ) { + return new Map_Contents_SpliteratorImpl<>(this.contents, seenKeys, unseenKeys, index, fence, expectedModCount); + } + + private Map_ContentsImpl _getContents() { + Map_ContentsImpl result = this.contents; + Engine.assume(result != null); + return result; + } + + private AbstractMapImpl _getMap() { + AbstractMapImpl result = _getContents().map; + Engine.assume(result != null); + return result; + } + + protected int _parentModCount() { + return _getMap().modCount; + } + + protected int _storageSize() { + return _getContents()._getStorage().size(); + } + + protected int _defaultCharacteristics() { + return 0; + } + + public int characteristics() { + if (this.fence < 0 || this.index == 0 && this.fence == _storageSize()) + return LibSLGlobals.SPLITERATOR_SIZED | _defaultCharacteristics(); + + return _defaultCharacteristics(); + } + + public long estimateSize() { + return super.estimateSize(); + } + + private int _checkSizeOfUnseenKeys() { + int size = unseenKeys.size(); + if (size != estimateSize()) + error("invariant violation"); + + return size; + } + + private int _checkSizeOfSeenKeys() { + int size = seenKeys.size(); + if (size != index) + error("invariant violation"); + + return size; + } + + private LibSLRuntime.Map> _removeSeenKeys() { + LibSLRuntime.Map> storage = _getContents()._getStorage().duplicate(); + int size = _checkSizeOfSeenKeys(); + for (int i = 0; i < size; i++) { + K key = seenKeys.get(i); + storage.remove(key); + } + + return storage; + } + + public void forEachRemaining(Consumer userAction) { + if (userAction == null) + throw new NullPointerException(); + + int fence = _getFence(); + Map_ContentsImpl contents = _getContents(); + if (unseenKeys != null) { + _checkSizeOfSeenKeys(); + int size = _checkSizeOfUnseenKeys(); + LibSLRuntime.Map> storage = contents._getStorage(); + for (int i = 0; i < size; i++) { + K key = unseenKeys.get(i); + userAction.accept(contents._contentByKey(storage, key)); + } + unseenKeys.copy(seenKeys, 0, 0, size); + } else { + LibSLRuntime.Map> unseenStorage = _removeSeenKeys(); + for (int i = this.index; i < fence; i++) { + K key = unseenStorage.anyKey(); + userAction.accept(contents._contentByKey(unseenStorage, key)); + unseenStorage.remove(key); + seenKeys.insert(i, key); + } + } + + this.index = fence; + _checkForModification(); + } + + public long getExactSizeIfKnown() { + return super.getExactSizeIfKnown(); + } + + public boolean tryAdvance(Consumer userAction) { + if (userAction == null) + throw new NullPointerException(); + + int hi = _getFence(); + if (this.index >= hi) + return false; + + Map_ContentsImpl contents = _getContents(); + if (unseenKeys != null) { + _checkSizeOfSeenKeys(); + _checkSizeOfUnseenKeys(); + K key = unseenKeys.get(0); + LibSLRuntime.Map> storage = contents._getStorage(); + userAction.accept(contents._contentByKey(storage, key)); + unseenKeys.remove(0); + seenKeys.insert(this.index, key); + } else { + LibSLRuntime.Map> unseenStorage = _removeSeenKeys(); + K key = unseenStorage.anyKey(); + userAction.accept(contents._contentByKey(unseenStorage, key)); + seenKeys.insert(this.index, key); + } + + this.index++; + _checkForModification(); + + return true; + } + + public Map_Contents_SpliteratorImpl trySplit() { + int hi = _getFence(); + int lo = this.index; + int mid = (hi + lo) >>> 1; + if (lo >= mid) + return null; + + LibSLRuntime.Map> unseenStorage = _removeSeenKeys(); + SymbolicList newUnseenKeys = Engine.makeSymbolicList(); + SymbolicList newSeenKeys = Engine.makeSymbolicList(); + + int j = 0; + for (int i = lo; i < mid; i++) { + K key = unseenStorage.anyKey(); + seenKeys.insert(i, key); + newUnseenKeys.insert(j++, key); + } + + this.index = mid; + return _createSpliterator(newSeenKeys, newUnseenKeys, lo, mid, this.expectedModCount); + } +} diff --git a/approximations/src/main/java/generated/java/util/map/Map_EntrySetImpl.java b/approximations/src/main/java/generated/java/util/map/Map_EntrySetImpl.java new file mode 100644 index 00000000..2e8d4ccd --- /dev/null +++ b/approximations/src/main/java/generated/java/util/map/Map_EntrySetImpl.java @@ -0,0 +1,146 @@ +package generated.java.util.map; + +import java.lang.Object; +import java.lang.String; +import java.util.*; +import java.util.function.Consumer; +import java.util.function.IntFunction; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import runtime.LibSLRuntime; +import stub.java.util.map.Map_EntrySet; + +@Approximate(Map_EntrySet.class) +public final class Map_EntrySetImpl extends Map_ContentsSetImpl> { + + public Map_EntrySetImpl(AbstractMapImpl parent) { + super(parent); + } + + Map.Entry _contentByKey(LibSLRuntime.Map> storage, K key) { + return storage.get(key); + } + + public boolean add(Map.Entry e) { + return super._add(e); + } + + public boolean addAll(@NotNull Collection> c) { + return super._addAll(c); + } + + public void clear() { + super._clear(); + } + + @SuppressWarnings("unchecked") + boolean _containsInStorage(LibSLRuntime.Map> storage, Object o) { + if (o instanceof Map.Entry) { + Map.Entry oEntry = (Map.Entry) o; + K key = oEntry.getKey(); + if (storage.hasKey(key)) { + Map.Entry entry = storage.get(key); + return LibSLRuntime.equals(entry, oEntry); + } + } + return false; + } + + public boolean contains(Object o) { + return super._contains(o); + } + + public boolean containsAll(@NotNull Collection c) { + return super._containsAll(c); + } + + public boolean equals(Object other) { + return super._equals(other); + } + + public void forEach(Consumer> userAction) { + super._forEach(userAction); + } + + public int hashCode() { + return super._hashCode(); + } + + public boolean isEmpty() { + return super._isEmpty(); + } + + @NotNull + public Iterator> iterator() { + return super._iterator(); + } + + public Stream> parallelStream() { + return super._parallelStream(); + } + + @SuppressWarnings("unchecked") + public boolean remove(Object o) { + if (!(o instanceof Map.Entry)) + return false; + + Map.Entry typedOtherEntry = (Map.Entry) o; + K key = typedOtherEntry.getKey(); + LibSLRuntime.Map> storage = _getStorage(); + if (storage.hasKey(key)) { + Map.Entry entry = storage.get(key); + if (LibSLRuntime.equals(entry, typedOtherEntry)) { + storage.remove(key); + this.map.modCount++; + return true; + } + } + + return false; + } + + public boolean removeAll(@NotNull Collection c) { + return super._removeAll(c); + } + + public boolean removeIf(Predicate> filter) { + return super._removeIf(filter); + } + + public boolean retainAll(@NotNull Collection c) { + return super._retainAll(c); + } + + public int size() { + return super._size(); + } + + public Spliterator> spliterator() { + return super._spliterator(); + } + + public Stream> stream() { + return super._stream(); + } + + @NotNull + public Object[] toArray() { + return super._toArray(); + } + + public T[] toArray(IntFunction generator) { + return super._toArray(generator); + } + + @NotNull + public T[] toArray(@NotNull T[] array) { + return super._toArray(array); + } + + public String toString() { + return super._toString(); + } +} diff --git a/approximations/src/main/java/generated/java/util/map/Map_KeySetImpl.java b/approximations/src/main/java/generated/java/util/map/Map_KeySetImpl.java new file mode 100644 index 00000000..a320675b --- /dev/null +++ b/approximations/src/main/java/generated/java/util/map/Map_KeySetImpl.java @@ -0,0 +1,131 @@ +package generated.java.util.map; + +import java.lang.Object; +import java.lang.String; +import java.util.*; +import java.util.function.Consumer; +import java.util.function.IntFunction; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import runtime.LibSLRuntime; +import stub.java.util.map.Map_KeySet; + +@Approximate(Map_KeySet.class) +public final class Map_KeySetImpl extends Map_ContentsSetImpl { + + public Map_KeySetImpl(AbstractMapImpl parent) { + super(parent); + } + + K _contentByKey(LibSLRuntime.Map> storage, K key) { + return key; + } + + public boolean add(K e) { + return super._add(e); + } + + public boolean addAll(@NotNull Collection c) { + return super._addAll(c); + } + + public void clear() { + super._clear(); + } + + @SuppressWarnings("unchecked") + boolean _containsInStorage(LibSLRuntime.Map> storage, Object o) { + return storage.hasKey((K) o); + } + + public boolean contains(Object key) { + return super._contains(key); + } + + public boolean containsAll(@NotNull Collection c) { + return super._containsAll(c); + } + + public boolean equals(Object other) { + return super._equals(other); + } + + public void forEach(Consumer userAction) { + super._forEach(userAction); + } + + public int hashCode() { + return super._hashCode(); + } + + public boolean isEmpty() { + return super._isEmpty(); + } + + @NotNull + public Iterator iterator() { + return super._iterator(); + } + + public Stream parallelStream() { + return super._parallelStream(); + } + + @SuppressWarnings("unchecked") + public boolean remove(Object key) { + K typedKey = (K) key; + LibSLRuntime.Map> storage = _getStorage(); + if (storage.hasKey(typedKey)) { + storage.remove(typedKey); + this.map.modCount++; + return true; + } + + return false; + } + + public boolean removeAll(@NotNull Collection c) { + return super._removeAll(c); + } + + public boolean removeIf(Predicate filter) { + return super._removeIf(filter); + } + + public boolean retainAll(@NotNull Collection c) { + return super._retainAll(c); + } + + public int size() { + return super._size(); + } + + public Spliterator spliterator() { + return super._spliterator(); + } + + public Stream stream() { + return super._stream(); + } + + @NotNull + public Object[] toArray() { + return super._toArray(); + } + + public T[] toArray(IntFunction generator) { + return super._toArray(generator); + } + + @NotNull + public T[] toArray(@NotNull T[] array) { + return super._toArray(array); + } + + public String toString() { + return super._toString(); + } +} diff --git a/approximations/src/main/java/generated/java/util/map/Map_ValuesImpl.java b/approximations/src/main/java/generated/java/util/map/Map_ValuesImpl.java new file mode 100644 index 00000000..c6edae3e --- /dev/null +++ b/approximations/src/main/java/generated/java/util/map/Map_ValuesImpl.java @@ -0,0 +1,145 @@ +package generated.java.util.map; + +import java.lang.Object; +import java.lang.String; +import java.util.*; +import java.util.function.Consumer; +import java.util.function.IntFunction; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; +import stub.java.util.map.Map_Values; + +@Approximate(Map_Values.class) +public class Map_ValuesImpl extends Map_ContentsImpl { + + public Map_ValuesImpl(AbstractMapImpl parent) { + super(parent); + } + + V _contentByKey(LibSLRuntime.Map> storage, K key) { + Map.Entry entry = storage.get(key); + return entry.getValue(); + } + + public boolean add(V e) { + return super._add(e); + } + + public boolean addAll(@NotNull Collection c) { + return super._addAll(c); + } + + public void clear() { + super._clear(); + } + + boolean _containsInStorage(LibSLRuntime.Map> storage, Object value) { + LibSLRuntime.Map> unseen = _getStorage().duplicate(); + int size = unseen.size(); + Engine.assume(size > 0); + for (int i = 0; i < size; i++) { + K key = unseen.anyKey(); + Map.Entry entry = unseen.get(key); + V curValue = entry.getValue(); + if (LibSLRuntime.equals(curValue, value)) + return true; + + unseen.remove(key); + } + + return false; + } + + public boolean contains(Object value) { + return super._contains(value); + } + + public boolean containsAll(@NotNull Collection c) { + return super._containsAll(c); + } + + public void forEach(Consumer userAction) { + super._forEach(userAction); + } + + public boolean isEmpty() { + return super._isEmpty(); + } + + @NotNull + public Iterator iterator() { + return super._iterator(); + } + + public Stream parallelStream() { + return super._parallelStream(); + } + + public boolean remove(Object value) { + LibSLRuntime.Map> storage = _getStorage(); + LibSLRuntime.Map> unseen = storage.duplicate(); + int size = unseen.size(); + Engine.assume(size >= 0); + for (int i = 0; i < size; i++) { + K key = unseen.anyKey(); + Map.Entry entry = unseen.get(key); + V curValue = entry.getValue(); + if (LibSLRuntime.equals(curValue, value)) { + storage.remove(key); + this.map.modCount++; + return true; + } + + unseen.remove(key); + } + + return false; + } + + public boolean removeAll(@NotNull Collection c) { + return super._removeAll(c); + } + + public boolean removeIf(Predicate filter) { + return super._removeIf(filter); + } + + public boolean retainAll(@NotNull Collection c) { + return super._retainAll(c); + } + + public int size() { + return super._size(); + } + + public Spliterator spliterator() { + return super._spliterator(); + } + + public Stream stream() { + return super._stream(); + } + + @NotNull + public Object[] toArray() { + return super._toArray(); + } + + public T[] toArray(IntFunction generator) { + return super._toArray(generator); + } + + @NotNull + public T[] toArray(@NotNull T[] array) { + return super._toArray(array); + } + + public String toString() { + return super._toString(); + } +} diff --git a/approximations/src/main/java/generated/java/util/optional/OptionalDoubleImpl.java b/approximations/src/main/java/generated/java/util/optional/OptionalDoubleImpl.java new file mode 100644 index 00000000..a049296e --- /dev/null +++ b/approximations/src/main/java/generated/java/util/optional/OptionalDoubleImpl.java @@ -0,0 +1,169 @@ +package generated.java.util.optional; + +import java.lang.NullPointerException; +import java.lang.Object; +import java.lang.Runnable; +import java.lang.String; +import java.util.NoSuchElementException; +import java.util.function.DoubleConsumer; +import java.util.function.DoubleSupplier; +import java.util.function.Supplier; +import java.util.stream.DoubleStream; + +import generated.java.util.stream.DoubleStreamImpl; +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +@SuppressWarnings("unused") +@Approximate(java.util.OptionalDouble.class) +public final class OptionalDoubleImpl { + + private static final OptionalDoubleImpl EMPTY = new OptionalDoubleImpl(0.0d, false); + + static { + Engine.assume(true); + } + + public double value; + + public boolean isPresent; + + public OptionalDoubleImpl(double value, boolean isPresent) { + this.value = value; + this.isPresent = isPresent; + } + + private OptionalDoubleImpl() { + LibSLRuntime.error("Private constructor call"); + } + + private OptionalDoubleImpl(double x) { + LibSLRuntime.error("Private constructor call"); + } + + public static OptionalDoubleImpl empty() { + return EMPTY; + } + + public static OptionalDoubleImpl of(double x) { + return new OptionalDoubleImpl(x, true); + } + + @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") + public boolean equals(Object other) { + if (other == this) + return true; + + if (Engine.typeIs(other, OptionalDoubleImpl.class)) { + OptionalDoubleImpl otherOptional = (OptionalDoubleImpl) other; + double otherValue = otherOptional.value; + boolean otherPresent = otherOptional.isPresent; + if (this.isPresent && otherPresent) + return LibSLRuntime.equals(this.value, otherValue); + + return this.isPresent == otherPresent; + } + + return false; + } + + public double getAsDouble() { + if (!this.isPresent) + throw new NoSuchElementException("No value present"); + + return this.value; + } + + public int hashCode() { + if (this.isPresent) + return LibSLRuntime.hashCode(this.value); + + return 0; + } + + public void ifPresent(DoubleConsumer consumer) { + if (!this.isPresent) + return; + + if (consumer == null) + throw new NullPointerException(); + + consumer.accept(this.value); + } + + public void ifPresentOrElse(DoubleConsumer consumer, Runnable emptyAction) { + if (this.isPresent) { + if (consumer == null) + throw new NullPointerException(); + + consumer.accept(this.value); + return; + } + + if (emptyAction == null) + throw new NullPointerException(); + + emptyAction.run(); + } + + public boolean isEmpty() { + return !this.isPresent; + } + + public boolean isPresent() { + return this.isPresent; + } + + public double orElse(double other) { + if (this.isPresent) + return this.value; + + return other; + } + + public double orElseGet(DoubleSupplier supplier) { + if (this.isPresent) + return this.value; + + return supplier.getAsDouble(); + } + + public double orElseThrow() { + if (!this.isPresent) + throw new NoSuchElementException("No value present"); + + return this.value; + } + + public double orElseThrow(Supplier exceptionSupplier) throws Throwable { + if (exceptionSupplier == null) + throw new NullPointerException(); + + if (!this.isPresent) + throw exceptionSupplier.get(); + + return this.value; + } + + public DoubleStream stream() { + double[] items; + if (this.isPresent) { + items = new double[1]; + items[0] = this.value; + } else { + items = new double[0]; + } + + return new DoubleStreamImpl(items); + } + + public String toString() { + if (this.isPresent) { + String valueStr = LibSLRuntime.toString(this.value); + return "OptionalDouble[".concat(valueStr).concat("]"); + } + + return "OptionalDouble.empty"; + } +} diff --git a/approximations/src/main/java/generated/java/util/optional/OptionalImpl.java b/approximations/src/main/java/generated/java/util/optional/OptionalImpl.java new file mode 100644 index 00000000..2e5071ed --- /dev/null +++ b/approximations/src/main/java/generated/java/util/optional/OptionalImpl.java @@ -0,0 +1,216 @@ +package generated.java.util.optional; + +import java.lang.NullPointerException; +import java.lang.Object; +import java.lang.Runnable; +import java.lang.String; +import java.util.NoSuchElementException; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.stream.Stream; + +import generated.java.util.stream.StreamStubImpl; +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +@SuppressWarnings("unused") +@Approximate(java.util.Optional.class) +public final class OptionalImpl { + + private static final OptionalImpl EMPTY = new OptionalImpl<>(null); + + static { + Engine.assume(true); + } + + public T value; + + private OptionalImpl(T value) { + this.value = value; + } + + private OptionalImpl() { + LibSLRuntime.error("Private constructor call"); + } + + @SuppressWarnings("unchecked") + public static OptionalImpl empty() { + return (OptionalImpl) EMPTY; + } + + public static OptionalImpl of(T obj) { + return new OptionalImpl<>(obj); + } + + public static OptionalImpl ofNullable(T obj) { + if (obj == null) + return empty(); + + return new OptionalImpl<>(obj); + } + + @SuppressWarnings({"unchecked", "EqualsWhichDoesntCheckParameterClass"}) + public boolean equals(Object other) { + if (other == this) + return true; + + if (Engine.typeIs(other, OptionalImpl.class)) { + T otherValue = ((OptionalImpl) other).value; + return LibSLRuntime.equals(this.value, otherValue); + } + + return false; + } + + public OptionalImpl filter(Predicate predicate) { + if (predicate == null) + throw new NullPointerException(); + + if (isEmpty()) + return this; + + if (predicate.test(this.value)) + return this; + + return empty(); + } + + @SuppressWarnings("unchecked") + public OptionalImpl flatMap(Function> mapper) { + if (mapper == null) + throw new NullPointerException(); + + if (isEmpty()) + return empty(); + + OptionalImpl result = (OptionalImpl) mapper.apply(this.value); + if (result == null) + throw new NullPointerException(); + + return result; + } + + public T get() { + if (isEmpty()) + throw new NoSuchElementException("No value present"); + + return this.value; + } + + public int hashCode() { + return LibSLRuntime.hashCode(this.value); + } + + public void ifPresent(Consumer consumer) { + if (isEmpty()) + return; + + if (consumer == null) + throw new NullPointerException(); + + consumer.accept(this.value); + } + + public void ifPresentOrElse(Consumer consumer, Runnable emptyAction) { + if (isPresent()) { + if (consumer == null) + throw new NullPointerException(); + + consumer.accept(this.value); + return; + } + + if (emptyAction == null) + throw new NullPointerException(); + + emptyAction.run(); + } + + public boolean isEmpty() { + return this.value == null; + } + + public boolean isPresent() { + return !isEmpty(); + } + + public OptionalImpl map(Function mapper) { + if (mapper == null) + throw new NullPointerException(); + + if (isEmpty()) + return empty(); + + U mappedValue = mapper.apply(this.value); + if (mappedValue == null) + return empty(); + + return new OptionalImpl<>(mappedValue); + } + + @SuppressWarnings("unchecked") + public OptionalImpl or(Supplier> supplier) { + if (supplier == null) + throw new NullPointerException(); + + if (isPresent()) + return this; + + OptionalImpl result = (OptionalImpl) supplier.get(); + if (result == null) + throw new NullPointerException(); + + return result; + } + + public T orElse(T other) { + if (isEmpty()) + return other; + + return this.value; + } + + public T orElseGet(Supplier supplier) { + if (isEmpty()) + return supplier.get(); + + return this.value; + } + + public T orElseThrow() { + if (isEmpty()) + throw new NoSuchElementException("No value present"); + + return this.value; + } + + public T orElseThrow(Supplier exceptionSupplier) throws X { + if (isEmpty()) + throw exceptionSupplier.get(); + + return this.value; + } + + @SuppressWarnings("unchecked") + public Stream stream() { + T[] items; + if (isEmpty()) { + items = (T[]) new Object[0]; + } else { + items = (T[]) new Object[1]; + items[0] = this.value; + } + return new StreamStubImpl<>(items); + } + + public String toString() { + if (isEmpty()) + return "Optional.empty"; + + String valueStr = LibSLRuntime.toString(this.value); + return "Optional[".concat(valueStr).concat("]"); + } +} diff --git a/approximations/src/main/java/generated/java/util/optional/OptionalIntImpl.java b/approximations/src/main/java/generated/java/util/optional/OptionalIntImpl.java new file mode 100644 index 00000000..9844f30b --- /dev/null +++ b/approximations/src/main/java/generated/java/util/optional/OptionalIntImpl.java @@ -0,0 +1,168 @@ +package generated.java.util.optional; + +import java.lang.NullPointerException; +import java.lang.Object; +import java.lang.Runnable; +import java.lang.String; +import java.util.NoSuchElementException; +import java.util.function.IntConsumer; +import java.util.function.IntSupplier; +import java.util.function.Supplier; +import java.util.stream.IntStream; + +import generated.java.util.stream.IntStreamImpl; +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +@SuppressWarnings("unused") +@Approximate(java.util.OptionalInt.class) +public final class OptionalIntImpl { + + private static final OptionalIntImpl EMPTY = new OptionalIntImpl(0, false); + + static { + Engine.assume(true); + } + + public int value; + + public boolean isPresent; + + public OptionalIntImpl(int value, boolean isPresent) { + this.value = value; + this.isPresent = isPresent; + } + + private OptionalIntImpl() { + LibSLRuntime.error("Private constructor call"); + } + + private OptionalIntImpl(int x) { + LibSLRuntime.error("Private constructor call"); + } + + public static OptionalIntImpl empty() { + return EMPTY; + } + + public static OptionalIntImpl of(int x) { + return new OptionalIntImpl(x, true); + } + + @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") + public boolean equals(Object other) { + if (other == this) + return true; + + if (Engine.typeIs(other, OptionalIntImpl.class)) { + OptionalIntImpl otherOptional = (OptionalIntImpl) other; + int otherValue = otherOptional.value; + boolean otherPresent = otherOptional.isPresent; + if (this.isPresent && otherPresent) + return this.value == otherValue; + + return this.isPresent == otherPresent; + } + + return false; + } + + public int getAsInt() { + if (!this.isPresent) + throw new NoSuchElementException("No value present"); + + return this.value; + } + + public int hashCode() { + if (this.isPresent) + return LibSLRuntime.hashCode(this.value); + + return 0; + } + + public void ifPresent(IntConsumer consumer) { + if (!this.isPresent) + return; + + if (consumer == null) + throw new NullPointerException(); + + consumer.accept(this.value); + } + + public void ifPresentOrElse(IntConsumer consumer, Runnable emptyAction) { + if (this.isPresent) { + if (consumer == null) { + throw new NullPointerException(); + } + consumer.accept(this.value); + return; + } + + if (emptyAction == null) { + throw new NullPointerException(); + } + emptyAction.run(); + } + + public boolean isEmpty() { + return !this.isPresent; + } + + public boolean isPresent() { + return this.isPresent; + } + + public int orElse(int other) { + if (this.isPresent) + return this.value; + + return other; + } + + public int orElseGet(IntSupplier supplier) { + if (this.isPresent) + return this.value; + + return supplier.getAsInt(); + } + + public int orElseThrow() { + if (!this.isPresent) + throw new NoSuchElementException("No value present"); + + return this.value; + } + + public int orElseThrow(Supplier exceptionSupplier) throws Throwable { + if (exceptionSupplier == null) + throw new NullPointerException(); + + if (!this.isPresent) + throw exceptionSupplier.get(); + + return this.value; + } + + public IntStream stream() { + int[] items; + if (this.isPresent) { + items = new int[1]; + items[0] = this.value; + } else { + items = new int[0]; + } + return new IntStreamImpl(items); + } + + public String toString() { + if (this.isPresent) { + String valueStr = LibSLRuntime.toString(this.value); + return "OptionalInt[".concat(valueStr).concat("]"); + } + + return "OptionalInt.empty"; + } +} diff --git a/approximations/src/main/java/generated/java/util/optional/OptionalLongImpl.java b/approximations/src/main/java/generated/java/util/optional/OptionalLongImpl.java new file mode 100644 index 00000000..d639da8f --- /dev/null +++ b/approximations/src/main/java/generated/java/util/optional/OptionalLongImpl.java @@ -0,0 +1,167 @@ +package generated.java.util.optional; + +import java.lang.NullPointerException; +import java.lang.Object; +import java.lang.Runnable; +import java.lang.String; +import java.util.NoSuchElementException; +import java.util.function.LongConsumer; +import java.util.function.LongSupplier; +import java.util.function.Supplier; +import java.util.stream.LongStream; + +import generated.java.util.stream.LongStreamImpl; +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +@SuppressWarnings("unused") +@Approximate(java.util.OptionalLong.class) +public final class OptionalLongImpl { + private static final OptionalLongImpl EMPTY = new OptionalLongImpl(0, false); + + static { + Engine.assume(true); + } + + public long value; + + public boolean isPresent; + + public OptionalLongImpl(long value, boolean isPresent) { + this.value = value; + this.isPresent = isPresent; + } + + private OptionalLongImpl() { + LibSLRuntime.error("Private constructor call"); + } + + private OptionalLongImpl(long x) { + LibSLRuntime.error("Private constructor call"); + } + + public static OptionalLongImpl empty() { + return EMPTY; + } + + public static OptionalLongImpl of(long x) { + return new OptionalLongImpl(x); + } + + @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") + public boolean equals(Object other) { + if (other == this) + return true; + + if (Engine.typeIs(other, OptionalLongImpl.class)) { + OptionalLongImpl otherOptional = (OptionalLongImpl) other; + long otherValue = otherOptional.value; + boolean otherPresent = otherOptional.isPresent; + if (this.isPresent && otherPresent) + return this.value == otherValue; + + return this.isPresent == otherPresent; + } + + return false; + } + + public long getAsLong() { + if (!this.isPresent) + throw new NoSuchElementException("No value present"); + + return this.value; + } + + public int hashCode() { + if (this.isPresent) + return LibSLRuntime.hashCode(this.value); + + return 0; + } + + public void ifPresent(LongConsumer consumer) { + if (!this.isPresent) + return; + + if (consumer == null) + throw new NullPointerException(); + + consumer.accept(this.value); + } + + public void ifPresentOrElse(LongConsumer consumer, Runnable emptyAction) { + if (this.isPresent) { + if (consumer == null) + throw new NullPointerException(); + + consumer.accept(this.value); + } else { + if (emptyAction == null) + throw new NullPointerException(); + + emptyAction.run(); + } + } + + public boolean isEmpty() { + return !this.isPresent; + } + + public boolean isPresent() { + return this.isPresent; + } + + public long orElse(long other) { + if (this.isPresent) + return this.value; + + return other; + } + + public long orElseGet(LongSupplier supplier) { + if (this.isPresent) + return this.value; + + return supplier.getAsLong(); + } + + public long orElseThrow() { + if (!this.isPresent) + throw new NoSuchElementException("No value present"); + + return this.value; + } + + public long orElseThrow(Supplier exceptionSupplier) throws Throwable { + if (exceptionSupplier == null) + throw new NullPointerException(); + + if (!this.isPresent) + throw exceptionSupplier.get(); + + return this.value; + } + + public LongStream stream() { + long[] items; + if (this.isPresent) { + items = new long[1]; + items[0] = this.value; + } else { + items = new long[0]; + } + + return new LongStreamImpl(items); + } + + public String toString() { + if (this.isPresent) { + String valueStr = LibSLRuntime.toString(this.value); + return "OptionalLong[".concat(valueStr).concat("]"); + } + + return "OptionalLong.empty"; + } +} diff --git a/approximations/src/main/java/generated/java/util/set/AbstractSetImpl.java b/approximations/src/main/java/generated/java/util/set/AbstractSetImpl.java new file mode 100644 index 00000000..a5d28e1d --- /dev/null +++ b/approximations/src/main/java/generated/java/util/set/AbstractSetImpl.java @@ -0,0 +1,389 @@ +package generated.java.util.set; + +import generated.java.util.AbstractCollectionImpl; +import generated.java.util.stream.StreamStubImpl; +import generated.runtime.LibSLGlobals; + +import java.lang.IllegalArgumentException; +import java.lang.NullPointerException; +import java.lang.Object; +import java.lang.String; +import java.util.*; +import java.util.function.Consumer; +import java.util.function.IntFunction; +import java.util.function.Predicate; +import java.util.stream.Stream; +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; + +@Approximate(java.util.AbstractSet.class) +public abstract class AbstractSetImpl extends AbstractCollectionImpl implements Set { + + public LibSLRuntime.Map storage; + + private boolean isHashSet; + + private static LibSLRuntime.Map.Container _createContainer(boolean isHashSet) { + if (isHashSet) + return new LibSLRuntime.HashMapContainer<>(); + + return new LibSLRuntime.IdentityMapContainer<>(); + } + + private static LibSLRuntime.Map _createstorage(boolean isHashSet) { + return new LibSLRuntime.Map<>(_createContainer(isHashSet)); + } + + public AbstractSetImpl(LibSLRuntime.Map storage, int modCount, boolean isHashSet) { + super(modCount); + this.storage = storage; + this.isHashSet = isHashSet; + } + + public AbstractSetImpl(boolean isHashSet) { + this(_createstorage(isHashSet), 0, isHashSet); + } + + @SuppressWarnings("unused") + public AbstractSetImpl(boolean isHashSet, Collection c) { + this(isHashSet); + _addAllElements(c); + } + + @SuppressWarnings("unused") + public AbstractSetImpl(boolean isHashSet, int initialCapacity) { + super(0); + + if (initialCapacity < 0) + throw new IllegalArgumentException(); + + this.storage = _createstorage(isHashSet); + this.isHashSet = isHashSet; + } + + @SuppressWarnings("unused") + public AbstractSetImpl(boolean isHashSet, int initialCapacity, float loadFactor) { + super(0); + + if (initialCapacity < 0) + throw new IllegalArgumentException(); + + if (loadFactor <= 0 || loadFactor != loadFactor) + throw new IllegalArgumentException(); + + this.storage = _createstorage(isHashSet); + this.isHashSet = isHashSet; + } + + @SuppressWarnings("unused") + public AbstractSetImpl(int initialCapacity, float loadFactor, boolean dummy) { + super(0); + LibSLRuntime.error("Private constructor call"); + } + + public LibSLRuntime.Map _getStorage() { + LibSLRuntime.Map storage = this.storage; + Engine.assume(storage != null); + return storage; + } + + private void __add(E key) { + _getStorage().set(key, LibSLGlobals.SOMETHING); + } + + @SuppressWarnings("unchecked") + public boolean _addAllElements(Collection c) { + LibSLRuntime.Map storage = _getStorage(); + int lengthBeforeAdd = storage.size(); + + if (c instanceof AbstractSetImpl) { + AbstractSetImpl other = (AbstractSetImpl) c; + LibSLRuntime.Map otherStorage = other._getStorage(); + storage.union(otherStorage); + } else { + for (E key : c) { + if (!storage.hasKey(key)) + __add(key); + } + } + + if (lengthBeforeAdd != storage.size()) { + this.modCount++; + return true; + } + + return false; + } + + protected Object[] _mapToArray() { + int size = _getStorage().size(); + Object[] items = new Object[size]; + LibSLRuntime.Map unseen = _getStorage().duplicate(); + for (int i = 0; i < size; i++) { + E key = unseen.anyKey(); + unseen.remove(key); + items[i] = key; + } + return items; + } + + @SuppressWarnings("unchecked") + public Stream _makeStream(boolean parallel) { + E[] items = (E[]) _mapToArray(); + return new StreamStubImpl<>(items, parallel); + } + + public boolean _add(E obj) { + LibSLRuntime.Map storage = _getStorage(); + this.modCount++; + if (storage.hasKey(obj)) + return false; + + storage.set(obj, LibSLGlobals.SOMETHING); + return true; + } + + public void _clear() { + this.storage = _createstorage(this.isHashSet); + this.modCount++; + } + + @SuppressWarnings("unchecked") + public Object _clone() throws CloneNotSupportedException { + AbstractSetImpl clonedSet = (AbstractSetImpl) super.clone(); + clonedSet.modCount = 0; + clonedSet.storage = _getStorage().duplicate(); + return clonedSet; + } + + @SuppressWarnings("unchecked") + public boolean _contains(Object obj) { + if (_isEmpty()) + return false; + + return _getStorage().hasKey((E) obj); + } + + public boolean _isEmpty() { + return _getStorage().size() == 0; + } + + @NotNull + public Iterator _iterator() { + LibSLRuntime.Map unseenKeys = _getStorage().duplicate(); + return new Set_IteratorImpl<>(this.modCount, unseenKeys, this, null); + } + + @SuppressWarnings("unchecked") + public boolean _remove(Object elem) { + E typedElem = (E) elem; + LibSLRuntime.Map storage = _getStorage(); + if (storage.hasKey(typedElem)) { + storage.remove(typedElem); + this.modCount++; + return true; + } + + return false; + } + + public int _size() { + return _getStorage().size(); + } + + public Spliterator _spliterator() { + return new Set_SpliteratorImpl<>(this); + } + + public boolean _equals(Object other) { + return __equals(other); + } + + @SuppressWarnings("unchecked") + boolean __equals(Object other) { + if (other == this) + return true; + + if (!(other instanceof Set)) + return false; + + int expectedModCount = this.modCount; + AbstractSetImpl otherSet = (AbstractSetImpl) other; + int otherExpectedModCount = otherSet.modCount; + LibSLRuntime.Map otherStorage = otherSet._getStorage(); + + LibSLRuntime.Map storage = _getStorage(); + if (storage.size() != otherStorage.size()) + return false; + + boolean result = LibSLRuntime.equals(storage, otherStorage); + otherSet._checkForModification(otherExpectedModCount); + this._checkForModification(expectedModCount); + + return result; + } + + public int _hashCode() { + return LibSLRuntime.hashCode(_getStorage()); + } + + @SuppressWarnings({"ConstantValue", "unchecked"}) + public boolean _removeAll(@NotNull Collection c) { + if (c == null) { + throw new NullPointerException(); + } + + int expectedModCount = this.modCount; + int otherSize = c.size(); + LibSLRuntime.Map storage = _getStorage(); + int lengthBeforeRemoving = storage.size(); + if (storage.size() > otherSize) { + for (Object key : c) { + E eKey = (E) key; + if (storage.hasKey(eKey)) + storage.remove(eKey); + } + } else { + LibSLRuntime.Map unseenKeys = storage.duplicate(); + int i = 0; + while (i < lengthBeforeRemoving) { + E key = unseenKeys.anyKey(); + unseenKeys.remove(key); + if (c.contains(key)) { + storage.remove(key); + } + i++; + } + } + _checkForModification(expectedModCount); + this.modCount++; + return lengthBeforeRemoving != storage.size(); + } + + @NotNull + public Object[] _toArray() { + return super._toArray(); + } + + @NotNull + public T[] _toArray(@NotNull T[] array) { + return super.toArray(array); + } + + public T[] _toArray(IntFunction generator) { + return super._toArray(generator); + } + + @SuppressWarnings("unchecked") + public boolean _containsAll(@NotNull Collection c) { + LibSLRuntime.Map storage = _getStorage(); + for (Object key : c) { + if (!storage.hasKey((E) key)) + return false; + } + + return true; + } + + public boolean _addAll(@NotNull Collection c) { + return _addAllElements(c); + } + + @SuppressWarnings("ConstantValue") + public boolean _retainAll(@NotNull Collection c) { + if (c == null) + throw new NullPointerException(); + + LibSLRuntime.Map storage = _getStorage(); + int lengthBeforeAdd = storage.size(); + LibSLRuntime.Map unseenKeys = storage.duplicate(); + int i = 0; + while (i < lengthBeforeAdd) { + E key = unseenKeys.anyKey(); + unseenKeys.remove(key); + if (!c.contains(key)) + storage.remove(key); + i++; + } + if (lengthBeforeAdd != storage.size()) { + this.modCount++; + return true; + } + + return false; + } + + public boolean _removeIf(Predicate filter) { + if (filter == null) + throw new NullPointerException(); + + LibSLRuntime.Map storage = _getStorage(); + int lengthBeforeAdd = storage.size(); + int expectedModCount = this.modCount; + LibSLRuntime.Map unseenKeys = storage.duplicate(); + int i = 0; + while (i < lengthBeforeAdd) { + E key = unseenKeys.anyKey(); + unseenKeys.remove(key); + if (filter.test(key)) + storage.remove(key); + i++; + } + _checkForModification(expectedModCount); + if (lengthBeforeAdd != storage.size()) { + this.modCount++; + return true; + } + + return false; + } + + public void _forEach(Consumer userAction) { + if (userAction == null) + throw new NullPointerException(); + + LibSLRuntime.Map storage = _getStorage(); + int count = storage.size(); + int expectedModCount = this.modCount; + LibSLRuntime.Map unseenKeys = storage.duplicate(); + int i = 0; + while (i < count) { + E key = unseenKeys.anyKey(); + unseenKeys.remove(key); + userAction.accept(key); + i++; + } + _checkForModification(expectedModCount); + } + + public Stream _stream() { + return _makeStream(false); + } + + public Stream _parallelStream() { + return _makeStream(true); + } + + public String _toString() { + LibSLRuntime.Map storage = _getStorage(); + int count = storage.size(); + if (count == 0) + return "[]"; + + Engine.assume(count > 0); + String result = "["; + LibSLRuntime.Map unseen = storage.duplicate(); + while (count != 0) { + E key = unseen.anyKey(); + unseen.remove(key); + result = result.concat(LibSLRuntime.toString(key)); + if (count > 1) + result = result.concat(", "); + count--; + } + + return result.concat("]"); + } +} diff --git a/approximations/src/main/java/generated/java/util/set/HashSetImpl.java b/approximations/src/main/java/generated/java/util/set/HashSetImpl.java new file mode 100644 index 00000000..d946be8f --- /dev/null +++ b/approximations/src/main/java/generated/java/util/set/HashSetImpl.java @@ -0,0 +1,143 @@ +package generated.java.util.set; + +import java.io.Serial; +import java.io.Serializable; +import java.lang.Object; +import java.lang.String; +import java.util.Collection; +import java.util.Iterator; +import java.util.Spliterator; +import java.util.function.Consumer; +import java.util.function.IntFunction; +import java.util.function.Predicate; +import java.util.stream.Stream; +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; + +@Approximate(java.util.HashSet.class) +public class HashSetImpl extends AbstractSetImpl implements Cloneable, Serializable { + + @Serial + private static final long serialVersionUID = -5024744406713321676L; + + static { + Engine.assume(true); + } + + public HashSetImpl() { + super(true); + } + + public HashSetImpl(Collection c) { + super(true, c); + } + + public HashSetImpl(int initialCapacity) { + super(true, initialCapacity); + } + + public HashSetImpl(int initialCapacity, float loadFactor) { + super(true, initialCapacity, loadFactor); + } + + @SuppressWarnings("unused") + private HashSetImpl(int initialCapacity, float loadFactor, boolean dummy) { + super(initialCapacity, loadFactor, dummy); + } + + public boolean add(E obj) { + return super._add(obj); + } + + public void clear() { + super._clear(); + } + + public Object clone() throws CloneNotSupportedException { + return super._clone(); + } + + public boolean contains(Object obj) { + return super._contains(obj); + } + + public boolean isEmpty() { + return super._isEmpty(); + } + + @NotNull + public Iterator iterator() { + return super._iterator(); + } + + public boolean remove(Object elem) { + return super._remove(elem); + } + + public int size() { + return super._size(); + } + + public Spliterator spliterator() { + return super._spliterator(); + } + + public boolean equals(Object other) { + return Engine.typeIs(other, HashSetImpl.class) && __equals(other); + } + + public int hashCode() { + return super._hashCode(); + } + + public boolean removeAll(@NotNull Collection c) { + return super._removeAll(c); + } + + @NotNull + public Object[] toArray() { + return super._toArray(); + } + + @NotNull + public T[] toArray(@NotNull T[] a) { + return super._toArray(a); + } + + public T[] toArray(IntFunction generator) { + return super._toArray(generator); + } + + public boolean containsAll(@NotNull Collection c) { + return super._containsAll(c); + } + + public boolean addAll(@NotNull Collection c) { + return super._addAll(c); + } + + public boolean retainAll(@NotNull Collection c) { + return super._retainAll(c); + } + + public boolean removeIf(Predicate filter) { + return super._removeIf(filter); + } + + public void forEach(Consumer userAction) { + super._forEach(userAction); + } + + public Stream stream() { + return super._stream(); + } + + public Stream parallelStream() { + return super._parallelStream(); + } + + public String toString() { + return super._toString(); + } +} diff --git a/approximations/src/main/java/generated/java/util/set/LinkedHashSetImpl.java b/approximations/src/main/java/generated/java/util/set/LinkedHashSetImpl.java new file mode 100644 index 00000000..cf6255f5 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/set/LinkedHashSetImpl.java @@ -0,0 +1,137 @@ +package generated.java.util.set; + +import java.io.Serial; +import java.io.Serializable; +import java.lang.Object; +import java.lang.String; +import java.util.*; +import java.util.function.Consumer; +import java.util.function.IntFunction; +import java.util.function.Predicate; +import java.util.stream.Stream; +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; + +@SuppressWarnings("unused") +@Approximate(java.util.LinkedHashSet.class) +public class LinkedHashSetImpl extends HashSetImpl implements Cloneable, Serializable { + + @Serial + private static final long serialVersionUID = -2851667679971038690L; + + static { + Engine.assume(true); + } + + public LinkedHashSetImpl() { + super(); + } + + public LinkedHashSetImpl(Collection c) { + super(c); + } + + public LinkedHashSetImpl(int initialCapacity) { + super(initialCapacity); + } + + public LinkedHashSetImpl(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + public boolean add(E obj) { + return super.add(obj); + } + + public void clear() { + super.clear(); + } + + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public boolean contains(Object obj) { + return super.contains(obj); + } + + public boolean isEmpty() { + return super.isEmpty(); + } + + @NotNull + public Iterator iterator() { + return super.iterator(); + } + + public boolean remove(Object elem) { + return super.remove(elem); + } + + public int size() { + return super.size(); + } + + public Spliterator spliterator() { + return super.spliterator(); + } + + public boolean equals(Object other) { + return Engine.typeIs(other, LinkedHashSetImpl.class) && __equals(other); + } + + public int hashCode() { + return super.hashCode(); + } + + public boolean removeAll(@NotNull Collection c) { + return super.removeAll(c); + } + + @NotNull + public Object[] toArray() { + return super.toArray(); + } + + @NotNull + public T[] toArray(@NotNull T[] a) { + return super.toArray(a); + } + + public T[] toArray(IntFunction generator) { + return super.toArray(generator); + } + + public boolean containsAll(@NotNull Collection c) { + return super.containsAll(c); + } + + public boolean addAll(@NotNull Collection c) { + return super.addAll(c); + } + + public boolean retainAll(@NotNull Collection c) { + return super.retainAll(c); + } + + public boolean removeIf(Predicate filter) { + return super.removeIf(filter); + } + + public void forEach(Consumer userAction) { + super.forEach(userAction); + } + + public Stream stream() { + return super.stream(); + } + + public Stream parallelStream() { + return super.parallelStream(); + } + + public String toString() { + return super.toString(); + } +} diff --git a/approximations/src/main/java/generated/java/util/set/Set_IteratorImpl.java b/approximations/src/main/java/generated/java/util/set/Set_IteratorImpl.java new file mode 100644 index 00000000..450cd3e0 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/set/Set_IteratorImpl.java @@ -0,0 +1,93 @@ +package generated.java.util.set; + +import java.lang.IllegalStateException; +import java.lang.NullPointerException; +import java.lang.Object; +import java.util.NoSuchElementException; +import java.util.function.Consumer; + +import generated.java.util.AbstractIteratorImpl; +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; +import stub.java.util.set.Set_Iterator; + +@Approximate(Set_Iterator.class) +public final class Set_IteratorImpl extends AbstractIteratorImpl { + + public AbstractSetImpl set; + + public LibSLRuntime.Map unseen; + + public E currentKey; + + public Set_IteratorImpl( + int expectedModCount, + LibSLRuntime.Map unseen, + AbstractSetImpl set, + E currentKey + ) { + super(expectedModCount); + this.unseen = unseen; + this.set = set; + this.currentKey = currentKey; + } + + private AbstractSetImpl _getSet() { + AbstractSetImpl result = this.set; + Engine.assume(result != null); + return result; + } + + protected int _parentModCount() { + return _getSet().modCount; + } + + private boolean _isEmpty() { + return this.unseen.size() == 0; + } + + public void forEachRemaining(Consumer userAction) { + if (userAction == null) + throw new NullPointerException(); + + int size = this.unseen.size(); + Engine.assume(size >= 0); + while (size > 0) { + _checkForModification(); + E curKey = this.unseen.anyKey(); + userAction.accept(curKey); + this.unseen.remove(curKey); + size--; + } + } + + public boolean hasNext() { + return !_isEmpty(); + } + + public E next() { + _checkForModification(); + if (_isEmpty()) + throw new NoSuchElementException(); + + E curKey = this.unseen.anyKey(); + this.unseen.remove(curKey); + this.currentKey = curKey; + return curKey; + } + + public void remove() { + E key = this.currentKey; + if (key == null) + throw new IllegalStateException(); + + _checkForModification(); + AbstractSetImpl set = _getSet(); + set._getStorage().remove(key); + set.modCount++; + this.unseen.remove(key); + this.expectedModCount = set.modCount; + this.currentKey = null; + } +} diff --git a/approximations/src/main/java/generated/java/util/set/Set_SpliteratorImpl.java b/approximations/src/main/java/generated/java/util/set/Set_SpliteratorImpl.java new file mode 100644 index 00000000..2afb32fe --- /dev/null +++ b/approximations/src/main/java/generated/java/util/set/Set_SpliteratorImpl.java @@ -0,0 +1,179 @@ +package generated.java.util.set; + +import generated.java.util.AbstractSpliteratorImpl; +import generated.runtime.LibSLGlobals; +import java.lang.NullPointerException; +import java.lang.Object; +import java.util.function.Consumer; +import org.jacodb.approximation.annotation.Approximate; +import org.usvm.api.Engine; +import org.usvm.api.SymbolicList; +import runtime.LibSLRuntime; +import stub.java.util.set.Set_Spliterator; + +import static runtime.LibSLRuntime.error; + +@Approximate(Set_Spliterator.class) +public final class Set_SpliteratorImpl extends AbstractSpliteratorImpl { + + AbstractSetImpl set; + + SymbolicList seenKeys; + + SymbolicList unseenKeys; + + Set_SpliteratorImpl( + AbstractSetImpl set, + SymbolicList seenKeys, + SymbolicList unseenKeys, + int index, + int fence, + int expectedModCount + ) { + super(index, fence, expectedModCount); + this.set = set; + this.seenKeys = seenKeys; + this.unseenKeys = unseenKeys; + } + + public Set_SpliteratorImpl(AbstractSetImpl set) { + this(set, Engine.makeSymbolicList(), null, 0, -1, 0); + } + + protected AbstractSpliteratorImpl _create(int index, int fence) { + return null; + } + + private AbstractSetImpl _getSet() { + AbstractSetImpl result = this.set; + Engine.assume(result != null); + return result; + } + + protected int _parentModCount() { + return _getSet().modCount; + } + + protected int _storageSize() { + return _getSet()._getStorage().size(); + } + + public int characteristics() { + if (this.fence < 0 || this.index == 0 && this.fence == _storageSize()) + return LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_DISTINCT; + + return LibSLGlobals.SPLITERATOR_DISTINCT; + } + + public long estimateSize() { + return super.estimateSize(); + } + + private int _checkSizeOfUnseenKeys() { + int size = unseenKeys.size(); + if (size != estimateSize()) + error("invariant violation"); + + return size; + } + + private int _checkSizeOfSeenKeys() { + int size = seenKeys.size(); + if (size != index) + error("invariant violation"); + + return size; + } + + private LibSLRuntime.Map _removeSeenKeys() { + LibSLRuntime.Map storage = _getSet()._getStorage().duplicate(); + int size = _checkSizeOfSeenKeys(); + for (int i = 0; i < size; i++) { + E key = seenKeys.get(i); + storage.remove(key); + } + + return storage; + } + + public void forEachRemaining(Consumer userAction) { + if (userAction == null) + throw new NullPointerException(); + + int fence = _getFence(); + if (unseenKeys != null) { + _checkSizeOfSeenKeys(); + int size = _checkSizeOfUnseenKeys(); + for (int i = 0; i < size; i++) { + E key = unseenKeys.get(i); + userAction.accept(key); + } + unseenKeys.copy(seenKeys, 0, 0, size); + } else { + LibSLRuntime.Map unseenStorage = _removeSeenKeys(); + for (int i = this.index; i < fence; i++) { + E key = unseenStorage.anyKey(); + userAction.accept(key); + unseenStorage.remove(key); + seenKeys.insert(i, key); + } + } + + this.index = fence; + _checkForModification(); + } + + public long getExactSizeIfKnown() { + return super.getExactSizeIfKnown(); + } + + public boolean tryAdvance(Consumer userAction) { + if (userAction == null) + throw new NullPointerException(); + + int hi = _getFence(); + if (this.index >= hi) + return false; + + if (unseenKeys != null) { + _checkSizeOfSeenKeys(); + _checkSizeOfUnseenKeys(); + E key = unseenKeys.get(0); + userAction.accept(key); + unseenKeys.remove(0); + seenKeys.insert(this.index, key); + } else { + LibSLRuntime.Map unseenStorage = _removeSeenKeys(); + E key = unseenStorage.anyKey(); + userAction.accept(key); + seenKeys.insert(this.index, key); + } + + this.index++; + _checkForModification(); + + return true; + } + + public Set_SpliteratorImpl trySplit() { + int hi = _getFence(); + int lo = this.index; + int mid = (hi + lo) >>> 1; + if (lo >= mid) + return null; + + LibSLRuntime.Map unseenStorage = _removeSeenKeys(); + SymbolicList newUnseenKeys = Engine.makeSymbolicList(); + SymbolicList newSeenKeys = Engine.makeSymbolicList(); + + int j = 0; + for (int i = lo; i < mid; i++) { + E key = unseenStorage.anyKey(); + seenKeys.insert(i, key); + newUnseenKeys.insert(j++, key); + } + + this.index = mid; + return new Set_SpliteratorImpl<>(this.set, newSeenKeys, newUnseenKeys, lo, mid, this.expectedModCount); + } +} diff --git a/approximations/src/main/java/generated/java/util/stream/BaseStreamImpl.java b/approximations/src/main/java/generated/java/util/stream/BaseStreamImpl.java new file mode 100644 index 00000000..df1dbe22 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/stream/BaseStreamImpl.java @@ -0,0 +1,106 @@ +package generated.java.util.stream; + +import generated.runtime.LibSLGlobals; +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; +import org.usvm.api.SymbolicList; +import stub.java.util.stream.BaseStreamStub; + +@Approximate(BaseStreamStub.class) +public abstract class BaseStreamImpl { + + private SymbolicList closeHandlers; + + public boolean isParallel; + + public boolean linkedOrConsumed; + + public int spliteratorCharacteristics = + LibSLGlobals.SPLITERATOR_ORDERED + | LibSLGlobals.SPLITERATOR_IMMUTABLE + | LibSLGlobals.SPLITERATOR_SIZED + | LibSLGlobals.SPLITERATOR_SUBSIZED; + + public BaseStreamImpl( + SymbolicList closeHandlers, + boolean isParallel, + boolean linkedOrConsumed + ) { + this.closeHandlers = closeHandlers; + this.isParallel = isParallel; + this.linkedOrConsumed = linkedOrConsumed; + } + + protected SymbolicList _getCloseHandlers() { + SymbolicList closeHandlers = this.closeHandlers; + Engine.assume(closeHandlers != null); + return closeHandlers; + } + + protected StreamStubImpl _copyToObjStream(T[] storage) { + return new StreamStubImpl<>(storage, _getCloseHandlers(), isParallel, linkedOrConsumed); + } + + protected IntStreamImpl _copyToIntStream(int[] storage) { + return new IntStreamImpl(storage, _getCloseHandlers(), isParallel, linkedOrConsumed); + } + + protected LongStreamImpl _copyToLongStream(long[] storage) { + return new LongStreamImpl(storage, _getCloseHandlers(), isParallel, linkedOrConsumed); + } + + protected DoubleStreamImpl _copyToDoubleStream(double[] storage) { + return new DoubleStreamImpl(storage, _getCloseHandlers(), isParallel, linkedOrConsumed); + } + + public void evaluate() { + if (this.linkedOrConsumed) + throw new IllegalStateException(); + + this.linkedOrConsumed = true; + } + + public boolean isParallel() { + return this.isParallel; + } + + @NotNull + public BaseStreamImpl sequential() { + this.isParallel = false; + return this; + } + + @NotNull + public BaseStreamImpl parallel() { + this.isParallel = true; + return this; + } + + abstract protected int _getLength(); + + public long count() { + evaluate(); + return _getLength(); + } + + @NotNull + public BaseStreamImpl onClose(@NotNull Runnable closeHandler) { + if (this.linkedOrConsumed) + throw new IllegalStateException(); + + int listLength = this.closeHandlers.size(); + this.closeHandlers.insert(listLength, closeHandler); + return this; + } + + public void close() { + int listLength = this.closeHandlers.size(); + for (int i = 0; i < listLength; i++) { + Runnable currentHandler = this.closeHandlers.get(i); + currentHandler.run(); + } + this.closeHandlers = Engine.makeSymbolicList(); + this.linkedOrConsumed = true; + } +} diff --git a/approximations/src/main/java/generated/java/util/stream/DoubleStreamImpl.java b/approximations/src/main/java/generated/java/util/stream/DoubleStreamImpl.java new file mode 100644 index 00000000..c5779c9b --- /dev/null +++ b/approximations/src/main/java/generated/java/util/stream/DoubleStreamImpl.java @@ -0,0 +1,655 @@ +package generated.java.util.stream; + +import generated.java.util.array.DoubleArrayIteratorImpl; +import generated.java.util.array.DoubleArraySpliteratorImpl; +import generated.runtime.LibSLGlobals; +import java.lang.Double; +import java.lang.IllegalArgumentException; +import java.lang.NullPointerException; +import java.lang.Object; +import java.lang.Runnable; +import java.util.*; +import java.util.function.BiConsumer; +import java.util.function.DoubleBinaryOperator; +import java.util.function.DoubleConsumer; +import java.util.function.DoubleFunction; +import java.util.function.DoublePredicate; +import java.util.function.DoubleToIntFunction; +import java.util.function.DoubleToLongFunction; +import java.util.function.DoubleUnaryOperator; +import java.util.function.ObjDoubleConsumer; +import java.util.function.Supplier; +import java.util.stream.DoubleStream; +import java.util.stream.Stream; + +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; +import org.usvm.api.SymbolicList; +import runtime.LibSLRuntime; +import stub.java.util.stream.*; +import generated.java.lang.DoubleImpl; + +@Approximate(DoubleStreamStub.class) +public class DoubleStreamImpl extends BaseStreamImpl implements DoubleStream { + + private final double[] storage; + + public DoubleStreamImpl( + double[] storage, + SymbolicList closeHandlers, + boolean isParallel, + boolean linkedOrConsumed + ) { + super(closeHandlers, isParallel, linkedOrConsumed); + this.storage = storage; + } + + public DoubleStreamImpl(double[] storage, SymbolicList closeHandlers, boolean isParallel) { + this(storage, closeHandlers, isParallel, false); + } + + public DoubleStreamImpl(double[] storage, SymbolicList closeHandlers) { + this(storage, closeHandlers, false); + } + + public DoubleStreamImpl(double[] storage) { + this(storage, Engine.makeSymbolicList()); + } + + private double[] _getStorage() { + double[] storage = this.storage; + Engine.assume(storage != null); + return storage; + } + + protected int _getLength() { + return _getStorage().length; + } + + private DoubleStreamImpl _copy(double[] storage) { + return new DoubleStreamImpl(storage, _getCloseHandlers(), isParallel, linkedOrConsumed); + } + + private DoubleStreamImpl _copy() { + return _copy(_getStorage()); + } + + private void _actionApply(DoubleConsumer _action) { + if (_action == null) + throw new NullPointerException(); + + double[] storage = _getStorage(); + for (double v : storage) { + _action.accept(v); + } + } + + private OptionalDouble _findFirst() { + double[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return OptionalDouble.empty(); + + double first = storage[0]; + return OptionalDouble.of(first); + } + + private double _sum() { + double[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return 0; + + double result = 0; + boolean anyNaN = false; + boolean anyPositiveInfinity = false; + boolean anyNegativeInfinity = false; + for (double element : storage) { + result += element; + if (element != element) + anyNaN = true; + if (element == DoubleImpl.POSITIVE_INFINITY) + anyPositiveInfinity = true; + if (element == DoubleImpl.NEGATIVE_INFINITY) + anyNegativeInfinity = true; + } + + if (anyNaN) + return DoubleImpl.NaN; + + if (anyPositiveInfinity && anyNegativeInfinity) + return DoubleImpl.NaN; + + if (anyPositiveInfinity && (result == DoubleImpl.NEGATIVE_INFINITY)) + return DoubleImpl.NaN; + + if (anyNegativeInfinity && (result == DoubleImpl.POSITIVE_INFINITY)) + return DoubleImpl.NaN; + + return result; + } + + @NotNull + @SuppressWarnings("ConstantValue") + public DoubleStreamImpl filter(@NotNull DoublePredicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + double[] storage = _getStorage(); + int length = storage.length; + double[] filteredStorage = Arrays.copyOf(storage, length); + int filteredLength = 0; + for (double e : storage) { + if (predicate.test(e)) { + filteredStorage[filteredLength] = e; + filteredLength++; + } + } + + Engine.assume(filteredLength <= length); + double[] resultStorage = Arrays.copyOf(filteredStorage, filteredLength); + return _copy(resultStorage); + } + + @NotNull + @SuppressWarnings("ConstantValue") + public DoubleStreamImpl map(@NotNull DoubleUnaryOperator mapper) { + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + double[] storage = _getStorage(); + int length = storage.length; + double[] mappedStorage = new double[length]; + for (int i = 0; i < length; i++) { + mappedStorage[i] = mapper.applyAsDouble(storage[i]); + } + + return _copy(mappedStorage); + } + + @NotNull + @SuppressWarnings({"unchecked", "ConstantValue"}) + public StreamStubImpl mapToObj(@NotNull DoubleFunction mapper) { + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + double[] storage = _getStorage(); + int length = storage.length; + T[] objStorage = (T[]) new Object[length]; + for (int i = 0; i < length; i++) { + objStorage[i] = mapper.apply(storage[i]); + } + + return _copyToObjStream(objStorage); + } + + @NotNull + @SuppressWarnings("ConstantValue") + public LongStreamImpl mapToLong(@NotNull DoubleToLongFunction mapper) { + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + double[] storage = _getStorage(); + int length = storage.length; + long[] mappedStorage = new long[length]; + for (int i = 0; i < length; i++) { + mappedStorage[i] = mapper.applyAsLong(storage[i]); + } + + return _copyToLongStream(mappedStorage); + } + + @NotNull + @SuppressWarnings("ConstantValue") + public IntStreamImpl mapToInt(@NotNull DoubleToIntFunction mapper) { + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + double[] storage = _getStorage(); + int length = storage.length; + int[] mappedStorage = new int[length]; + for (int i = 0; i < length; i++) { + mappedStorage[i] = mapper.applyAsInt(storage[i]); + } + + return _copyToIntStream(mappedStorage); + } + + @SuppressWarnings("ConstantValue") + public DoubleStream flatMap(@NotNull DoubleFunction mapper) { + // TODO: approximate + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + DoubleStream result = Engine.makeSymbolic(DoubleStream.class); + Engine.assume(result != null); + return result; + } + + @NotNull + public DoubleStreamImpl sorted() { + super.evaluate(); + + double[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return _copy(); + + int outerLimit = length - 1; + for (int i = 0; i < outerLimit; i++) { + int innerLimit = length - i - 1; + for (int j = 0; j < innerLimit; j++) { + int idxB = j + 1; + double a = storage[j]; + double b = storage[idxB]; + if (a > b) { + storage[j] = b; + storage[idxB] = a; + } + } + } + + return _copy(); + } + + @NotNull + public DoubleStreamImpl distinct() { + super.evaluate(); + + double[] storage = _getStorage(); + double[] distinctStorage; + int length = storage.length; + if (length == 0) { + distinctStorage = Arrays.copyOf(storage, 0); + return _copy(distinctStorage); + } + + int distinctLength = 0; + distinctStorage = Arrays.copyOf(storage, length); + LibSLRuntime.Map visited = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); + for (double item : storage) { + if (!visited.hasKey(item)) { + visited.set(item, LibSLGlobals.SOMETHING); + distinctStorage[distinctLength] = item; + distinctLength++; + } + } + + Engine.assume(distinctLength <= length); + double[] resultStorage = Arrays.copyOf(distinctStorage, distinctLength); + return _copy(resultStorage); + } + + @NotNull + public DoubleStreamImpl peek(@NotNull DoubleConsumer _action) { + super.evaluate(); + _actionApply(_action); + return _copy(); + } + + @NotNull + public DoubleStreamImpl limit(long maxSize) { + super.evaluate(); + + int maxSizeInt = (int) maxSize; + + if (maxSizeInt < 0) + throw new IllegalArgumentException(); + + if (maxSizeInt == 0) + return _copy(Arrays.copyOf(_getStorage(), 0)); + + double[] storage = _getStorage(); + int length = storage.length; + if (maxSizeInt > length) + return _copy(); + + double[] limitStorage = Arrays.copyOf(storage, maxSizeInt); + return _copy(limitStorage); + } + + @NotNull + public DoubleStreamImpl skip(long n) { + super.evaluate(); + + int offset = (int) n; + + if (offset < 0) + throw new IllegalArgumentException(); + + if (offset == 0) + return _copy(); + + double[] storage = _getStorage(); + int length = storage.length; + if (offset >= length) + return _copy(Arrays.copyOf(_getStorage(), 0)); + + double[] skipStorage = Arrays.copyOfRange(storage, offset, length); + return _copy(skipStorage); + } + + public void forEach(DoubleConsumer _action) { + super.evaluate(); + _actionApply(_action); + } + + public void forEachOrdered(DoubleConsumer _action) { + forEach(_action); + } + + public double[] toArray() { + super.evaluate(); + return _getStorage(); + } + + public double reduce(double identity, DoubleBinaryOperator accumulator) { + super.evaluate(); + + if (accumulator == null) + throw new NullPointerException(); + + double result = identity; + double[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return result; + + for (double item : storage) { + result = accumulator.applyAsDouble(result, item); + } + + return result; + } + + public OptionalDouble reduce(DoubleBinaryOperator accumulator) { + super.evaluate(); + + if (accumulator == null) + throw new NullPointerException(); + + double[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return OptionalDouble.empty(); + + double value = storage[0]; + for (int i = 1; i < length; i++) { + value = accumulator.applyAsDouble(value, storage[i]); + } + + return OptionalDouble.of(value); + } + + public R collect(Supplier supplier, ObjDoubleConsumer accumulator, BiConsumer combiner) { + super.evaluate(); + + if (supplier == null) + throw new NullPointerException(); + + if (accumulator == null) + throw new NullPointerException(); + + if (combiner == null) + throw new NullPointerException(); + + R result = supplier.get(); + double[] storage = _getStorage(); + for (double item : storage) { + accumulator.accept(result, item); + } + + return result; + } + + public OptionalDouble min() { + super.evaluate(); + + double[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return OptionalDouble.empty(); + + double min = storage[0]; + for (int i = 1; i < length; i++) { + double item = storage[i]; + if (min > item) + min = item; + } + + return OptionalDouble.of(min); + } + + public OptionalDouble max() { + super.evaluate(); + + double[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return OptionalDouble.empty(); + + double max = storage[0]; + for (int i = 1; i < length; i++) { + double item = storage[i]; + if (max < item) + max = item; + } + + return OptionalDouble.of(max); + } + + public long count() { + return super.count(); + } + + public boolean anyMatch(DoublePredicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + double[] storage = _getStorage(); + for (double item : storage) { + if (predicate.test(item)) + return true; + } + + return false; + } + + public boolean allMatch(DoublePredicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + double[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return true; + + for (double item : storage) { + if (!predicate.test(item)) + return false; + } + + return true; + } + + public boolean noneMatch(DoublePredicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + double[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return true; + + for (double item : storage) { + if (predicate.test(item)) + return false; + } + + return true; + } + + public OptionalDouble findFirst() { + super.evaluate(); + return _findFirst(); + } + + public OptionalDouble findAny() { + return findFirst(); + } + + @NotNull + public PrimitiveIterator.OfDouble iterator() { + super.evaluate(); + return new DoubleArrayIteratorImpl(_getStorage()); + } + + @NotNull + public Spliterator.OfDouble spliterator() { + super.evaluate(); + double[] storage = _getStorage(); + return new DoubleArraySpliteratorImpl(storage, spliteratorCharacteristics); + } + + public boolean isParallel() { + return super.isParallel(); + } + + @NotNull + public DoubleStreamImpl sequential() { + return (DoubleStreamImpl) super.sequential(); + } + + @NotNull + public DoubleStreamImpl parallel() { + return (DoubleStreamImpl) super.parallel(); + } + + @NotNull + public DoubleStreamImpl unordered() { + super.evaluate(); + return _copy(); + } + + @NotNull + public DoubleStreamImpl onClose(@NotNull Runnable closeHandler) { + return (DoubleStreamImpl) super.onClose(closeHandler); + } + + public void close() { + super.close(); + } + + @NotNull + @SuppressWarnings("ConstantValue") + public DoubleStreamImpl dropWhile(@NotNull DoublePredicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + double[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return _copy(Arrays.copyOf(storage, 0)); + + int dropLength = 0; + while (dropLength < length && predicate.test(storage[dropLength])) { + dropLength++; + } + + if (dropLength == 0) + return _copy(); + + int newLength = length - dropLength; + double[] newStorage = Arrays.copyOf(storage, newLength); + return _copy(newStorage); + } + + @NotNull + @SuppressWarnings("ConstantValue") + public DoubleStreamImpl takeWhile(@NotNull DoublePredicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + double[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return _copy(Arrays.copyOf(storage, 0)); + + int takeLength = 0; + while (takeLength < length && predicate.test(storage[takeLength])) { + takeLength++; + } + + if (takeLength == length) + return _copy(); + + double[] newStorage = Arrays.copyOf(storage, takeLength); + return _copy(newStorage); + } + + public double sum() { + super.evaluate(); + return _sum(); + } + + public OptionalDouble average() { + super.evaluate(); + + double[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return OptionalDouble.empty(); + + double curSum = _sum(); + double divisionResult = curSum / length; + return OptionalDouble.of(divisionResult); + } + + public DoubleSummaryStatistics summaryStatistics() { + super.evaluate(); + + double[] storage = _getStorage(); + DoubleSummaryStatistics result = new DoubleSummaryStatistics(); + for (double v : storage) { + result.accept(v); + } + + return result; + } + + public Stream boxed() { + super.evaluate(); + + double[] storage = _getStorage(); + int length = storage.length; + Double[] doubleArray = new Double[length]; + for (int i = 0; i < length; i++) { + doubleArray[i] = storage[i]; + } + + return _copyToObjStream(doubleArray); + } +} diff --git a/approximations/src/main/java/generated/java/util/stream/DoubleStreamLSL.java b/approximations/src/main/java/generated/java/util/stream/DoubleStreamLSL.java deleted file mode 100644 index e80d69ea..00000000 --- a/approximations/src/main/java/generated/java/util/stream/DoubleStreamLSL.java +++ /dev/null @@ -1,1286 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/stream/DoubleStream.lsl:26 -// - java/util/stream/DoubleStream.main.lsl:29 -// -package generated.java.util.stream; - -import generated.runtime.LibSLGlobals; -import java.lang.Double; -import java.lang.IllegalArgumentException; -import java.lang.IllegalStateException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.Runnable; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.DoubleSummaryStatistics; -import java.util.OptionalDouble; -import java.util.PrimitiveIterator; -import java.util.Spliterator; -import java.util.function.BiConsumer; -import java.util.function.DoubleBinaryOperator; -import java.util.function.DoubleConsumer; -import java.util.function.DoubleFunction; -import java.util.function.DoublePredicate; -import java.util.function.DoubleToIntFunction; -import java.util.function.DoubleToLongFunction; -import java.util.function.DoubleUnaryOperator; -import java.util.function.ObjDoubleConsumer; -import java.util.function.Supplier; -import java.util.stream.DoubleStream; -import java.util.stream.IntStream; -import java.util.stream.LongStream; -import java.util.stream.Stream; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import org.usvm.api.SymbolicList; -import runtime.LibSLRuntime; -import stub.java.util.Spliterators_DoubleArraySpliterator; - -/** - * DoubleStreamAutomaton for DoubleStreamLSL ~> java.util.stream.DoubleStreamLSL - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.stream.DoubleStreamLSL.class) -public class DoubleStreamLSL implements LibSLRuntime.Automaton, DoubleStream { - private static final double DOUBLE_POSITIVE_INFINITY = 1.0d / 0.0d; - - private static final double DOUBLE_NEGATIVE_INFINITY = -1.0d / 0.0d; - - private static final double DOUBLE_NAN = 0.0d / 0.0d; - - static { - Engine.assume(true); - } - - public double[] storage; - - public transient int length; - - public SymbolicList closeHandlers; - - public boolean isParallel; - - public boolean linkedOrConsumed; - - @LibSLRuntime.AutomatonConstructor - public DoubleStreamLSL(Void __$lsl_token, final byte p0, final double[] p1, final int p2, - final SymbolicList p3, final boolean p4, final boolean p5) { - this.storage = p1; - this.length = p2; - this.closeHandlers = p3; - this.isParallel = p4; - this.linkedOrConsumed = p5; - } - - @LibSLRuntime.AutomatonConstructor - public DoubleStreamLSL(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, 0, null, false, false); - } - - /** - * [SUBROUTINE] DoubleStreamAutomaton::_actionApply(DoubleConsumer) -> void - * Source: java/util/stream/DoubleStream.main.lsl:117 - */ - private void _actionApply(DoubleConsumer _action) { - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - int i = 0; - for (i = 0; i < this.length; i += 1) { - _action.accept(storage[i]); - } - ; - } - } - - /** - * [SUBROUTINE] DoubleStreamAutomaton::_findFirst() -> OptionalDouble - * Source: java/util/stream/DoubleStream.main.lsl:136 - */ - private OptionalDouble _findFirst() { - OptionalDouble result = null; - /* body */ { - if (this.length == 0) { - result = OptionalDouble.empty(); - } else { - final double first = storage[0]; - result = OptionalDouble.of(first); - } - } - return result; - } - - /** - * [SUBROUTINE] DoubleStreamAutomaton::_sum() -> double - * Source: java/util/stream/DoubleStream.main.lsl:150 - */ - private double _sum() { - double result = 0.0d; - /* body */ { - result = 0; - if (this.length != 0) { - boolean anyNaN = false; - boolean anyPositiveInfinity = false; - boolean anyNegativeInfinity = false; - int i = 0; - for (i = 0; i < this.length; i += 1) { - final double element = storage[i]; - result += element; - if (element != element) { - anyNaN = true; - } - if (element == DOUBLE_POSITIVE_INFINITY) { - anyPositiveInfinity = true; - } - if (element == DOUBLE_NEGATIVE_INFINITY) { - anyNegativeInfinity = true; - } - } - ; - if (anyNaN) { - result = DOUBLE_NAN; - } else { - if (anyPositiveInfinity && anyNegativeInfinity) { - result = DOUBLE_NAN; - } else { - if (anyPositiveInfinity && (result == DOUBLE_NEGATIVE_INFINITY)) { - result = DOUBLE_NAN; - } else { - if (anyNegativeInfinity && (result == DOUBLE_POSITIVE_INFINITY)) { - result = DOUBLE_NAN; - } - } - } - } - } - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::filter(DoubleStream, DoublePredicate) -> DoubleStream - * Source: java/util/stream/DoubleStream.main.lsl:197 - */ - public DoubleStream filter(DoublePredicate predicate) { - DoubleStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - double[] filteredStorage = new double[this.length]; - int filteredLength = 0; - int i = 0; - for (i = 0; i < this.length; i += 1) { - if (predicate.test(storage[i])) { - filteredStorage[filteredLength] = storage[i]; - filteredLength += 1; - } - } - ; - Engine.assume(filteredLength <= this.length); - double[] resultStorage = new double[filteredLength]; - LibSLRuntime.ArrayActions.copy(filteredStorage, 0, resultStorage, 0, filteredLength); - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ resultStorage, - /* length = */ filteredLength, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::map(DoubleStream, DoubleUnaryOperator) -> DoubleStream - * Source: java/util/stream/DoubleStream.main.lsl:238 - */ - public DoubleStream map(DoubleUnaryOperator mapper) { - DoubleStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (mapper == null) { - throw new NullPointerException(); - } - double[] mappedStorage = new double[this.length]; - int i = 0; - for (i = 0; i < this.length; i += 1) { - mappedStorage[i] = mapper.applyAsDouble(storage[i]); - } - ; - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ mappedStorage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::mapToObj(DoubleStream, DoubleFunction) -> Stream - * Source: java/util/stream/DoubleStream.main.lsl:269 - */ - public Stream mapToObj(DoubleFunction mapper) { - Stream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - final Object[] objStorage = new Object[this.length]; - int i = 0; - for (i = 0; i < this.length; i += 1) { - objStorage[i] = mapper.apply(storage[i]); - } - ; - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ objStorage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::mapToLong(DoubleStream, DoubleToLongFunction) -> LongStream - * Source: java/util/stream/DoubleStream.main.lsl:298 - */ - public LongStream mapToLong(DoubleToLongFunction mapper) { - LongStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (mapper == null) { - throw new NullPointerException(); - } - long[] mappedStorage = new long[this.length]; - int i = 0; - for (i = 0; i < this.length; i += 1) { - mappedStorage[i] = mapper.applyAsLong(storage[i]); - } - ; - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ mappedStorage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::mapToInt(DoubleStream, DoubleToIntFunction) -> IntStream - * Source: java/util/stream/DoubleStream.main.lsl:329 - */ - public IntStream mapToInt(DoubleToIntFunction mapper) { - IntStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (mapper == null) { - throw new NullPointerException(); - } - int[] mappedStorage = new int[this.length]; - int i = 0; - for (i = 0; i < this.length; i += 1) { - mappedStorage[i] = mapper.applyAsInt(storage[i]); - } - ; - result = (stub.java.util.stream.IntStreamLSL) ((Object) new IntStreamLSL((Void) null, - /* state = */ IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ mappedStorage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::flatMap(DoubleStream, DoubleFunction) -> DoubleStream - * Source: java/util/stream/DoubleStream.main.lsl:360 - */ - public DoubleStream flatMap(DoubleFunction mapper) { - DoubleStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (mapper == null) { - throw new NullPointerException(); - } - result = Engine.makeSymbolic(DoubleStream.class); - Engine.assume(result != null); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::sorted(DoubleStream) -> DoubleStream - * Source: java/util/stream/DoubleStream.main.lsl:376 - */ - public DoubleStream sorted() { - DoubleStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (this.length == 0) { - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ 0, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - Engine.assume(this.length > 0); - final int outerLimit = this.length - 1; - int innerLimit = 0; - int i = 0; - int j = 0; - for (i = 0; i < outerLimit; i += 1) { - innerLimit = (this.length - i) - 1; - for (j = 0; j < innerLimit; j += 1) { - final int idxA = j; - final int idxB = j + 1; - final double a = storage[idxA]; - final double b = storage[idxB]; - if (a > b) { - storage[idxA] = b; - storage[idxB] = a; - } - } - ; - } - ; - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::distinct(DoubleStream) -> DoubleStream - * Source: java/util/stream/DoubleStream.main.lsl:439 - */ - public DoubleStream distinct() { - DoubleStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - double[] distinctStorage = null; - int distinctLength = 0; - final int size = this.length; - if (size == 0) { - distinctStorage = new double[0]; - distinctLength = 0; - } else { - final double[] items = this.storage; - Engine.assume(items != null); - Engine.assume(items.length != 0); - Engine.assume(size == items.length); - int i = 0; - int j = 0; - final SymbolicList uniqueItems = Engine.makeSymbolicList(); - final LibSLRuntime.Map visited = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - for (i = 0; i < size; i += 1) { - final double item = items[i]; - if (!visited.hasKey(item)) { - visited.set(item, LibSLGlobals.SOMETHING); - uniqueItems.insert(j, item); - j += 1; - } - } - ; - distinctLength = j; - Engine.assume(distinctLength > 0); - Engine.assume(distinctLength <= size); - distinctStorage = new double[distinctLength]; - for (i = 0; i < distinctLength; i += 1) { - final Double item = uniqueItems.get(i); - Engine.assume(item != null); - distinctStorage[i] = ((double) item); - } - ; - } - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ distinctStorage, - /* length = */ distinctLength, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::peek(Stream, DoubleConsumer) -> DoubleStream - * Source: java/util/stream/DoubleStream.main.lsl:511 - */ - public DoubleStream peek(DoubleConsumer _action) { - DoubleStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - _actionApply(_action); - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::limit(DoubleStream, long) -> DoubleStream - * Source: java/util/stream/DoubleStream.main.lsl:527 - */ - public DoubleStream limit(long maxSize) { - DoubleStream result = null; - /* body */ { - final int maxSizeInt = ((int) maxSize); - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (maxSizeInt < 0) { - throw new IllegalArgumentException(); - } - if (maxSizeInt == 0) { - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ 0, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - if (maxSizeInt > this.length) { - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - final double[] limitStorage = new double[maxSizeInt]; - LibSLRuntime.ArrayActions.copy(this.storage, 0, limitStorage, 0, maxSizeInt); - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ limitStorage, - /* length = */ maxSizeInt, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::skip(DoubleStream, long) -> DoubleStream - * Source: java/util/stream/DoubleStream.main.lsl:569 - */ - public DoubleStream skip(long n) { - DoubleStream result = null; - /* body */ { - final int offset = ((int) n); - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (offset < 0) { - throw new IllegalArgumentException(); - } - if (offset == 0) { - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - if (offset >= this.length) { - double[] newArray = {}; - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ newArray, - /* length = */ 0, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - final int newLength = this.length - offset; - final double[] skipStorage = new double[newLength]; - int i = 0; - int skipIndex = 0; - for (i = offset; i < this.length; i += 1) { - skipStorage[skipIndex] = storage[i]; - skipIndex += 1; - } - ; - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ skipStorage, - /* length = */ newLength, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::forEach(DoubleStream, DoubleConsumer) -> void - * Source: java/util/stream/DoubleStream.main.lsl:625 - */ - public void forEach(DoubleConsumer _action) { - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - _actionApply(_action); - this.linkedOrConsumed = true; - } - } - - /** - * [FUNCTION] DoubleStreamAutomaton::forEachOrdered(DoubleStream, DoubleConsumer) -> void - * Source: java/util/stream/DoubleStream.main.lsl:634 - */ - public void forEachOrdered(DoubleConsumer _action) { - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - _actionApply(_action); - this.linkedOrConsumed = true; - } - } - - /** - * [FUNCTION] DoubleStreamAutomaton::toArray(DoubleStream) -> array - * Source: java/util/stream/DoubleStream.main.lsl:643 - */ - public double[] toArray() { - double[] result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = this.storage; - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::reduce(DoubleStream, double, DoubleBinaryOperator) -> double - * Source: java/util/stream/DoubleStream.main.lsl:652 - */ - public double reduce(double identity, DoubleBinaryOperator accumulator) { - double result = 0.0d; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (accumulator == null) { - throw new NullPointerException(); - } - result = identity; - if (this.length != 0) { - Engine.assume(this.length > 0); - int i = 0; - for (i = 0; i < this.length; i += 1) { - result = accumulator.applyAsDouble(result, storage[i]); - } - ; - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::reduce(DoubleStream, DoubleBinaryOperator) -> OptionalDouble - * Source: java/util/stream/DoubleStream.main.lsl:681 - */ - public OptionalDouble reduce(DoubleBinaryOperator accumulator) { - OptionalDouble result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (accumulator == null) { - throw new NullPointerException(); - } - if (this.length == 0) { - result = OptionalDouble.empty(); - } else { - if (this.length > 0) { - double value = storage[0]; - int i = 0; - for (i = 1; i < this.length; i += 1) { - value = accumulator.applyAsDouble(value, storage[i]); - } - ; - result = OptionalDouble.of(value); - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::collect(DoubleStream, Supplier, ObjDoubleConsumer, BiConsumer) -> Object - * Source: java/util/stream/DoubleStream.main.lsl:715 - */ - public Object collect(Supplier supplier, ObjDoubleConsumer accumulator, BiConsumer combiner) { - Object result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (supplier == null) { - throw new NullPointerException(); - } - if (accumulator == null) { - throw new NullPointerException(); - } - if (combiner == null) { - throw new NullPointerException(); - } - result = supplier.get(); - int i = 0; - for (i = 0; i < this.length; i += 1) { - accumulator.accept(result, storage[i]); - } - ; - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::min(DoubleStream) -> OptionalDouble - * Source: java/util/stream/DoubleStream.main.lsl:747 - */ - public OptionalDouble min() { - OptionalDouble result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (this.length == 0) { - result = OptionalDouble.empty(); - } else { - double min = storage[0]; - int i = 0; - for (i = 1; i < this.length; i += 1) { - if (min > storage[i]) { - min = storage[i]; - } - } - ; - result = OptionalDouble.of(min); - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::max(DoubleStream) -> OptionalDouble - * Source: java/util/stream/DoubleStream.main.lsl:779 - */ - public OptionalDouble max() { - OptionalDouble result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (this.length == 0) { - result = OptionalDouble.empty(); - } else { - double max = storage[0]; - int i = 0; - for (i = 1; i < this.length; i += 1) { - if (max < storage[i]) { - max = storage[i]; - } - } - ; - result = OptionalDouble.of(max); - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::count(DoubleStream) -> long - * Source: java/util/stream/DoubleStream.main.lsl:811 - */ - public long count() { - long result = 0L; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = this.length; - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::anyMatch(DoubleStream, DoublePredicate) -> boolean - * Source: java/util/stream/DoubleStream.main.lsl:820 - */ - public boolean anyMatch(DoublePredicate predicate) { - boolean result = false; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - result = false; - int i = 0; - while ((i < this.length) && !predicate.test(storage[i])) { - i += 1; - } - ; - if (i < this.length) { - result = true; - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::allMatch(DoubleStream, DoublePredicate) -> boolean - * Source: java/util/stream/DoubleStream.main.lsl:848 - */ - public boolean allMatch(DoublePredicate predicate) { - boolean result = false; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - result = true; - if (this.length > 0) { - result = false; - int i = 0; - while ((i < this.length) && predicate.test(storage[i])) { - i += 1; - } - ; - if (i == this.length) { - result = true; - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::noneMatch(DoubleStream, DoublePredicate) -> boolean - * Source: java/util/stream/DoubleStream.main.lsl:874 - */ - public boolean noneMatch(DoublePredicate predicate) { - boolean result = false; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - result = true; - if (this.length > 0) { - result = false; - int i = 0; - while ((i < this.length) && !predicate.test(storage[i])) { - i += 1; - } - ; - if (i == this.length) { - result = true; - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::findFirst(DoubleStream) -> OptionalDouble - * Source: java/util/stream/DoubleStream.main.lsl:900 - */ - public OptionalDouble findFirst() { - OptionalDouble result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = _findFirst(); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::findAny(DoubleStream) -> OptionalDouble - * Source: java/util/stream/DoubleStream.main.lsl:909 - */ - public OptionalDouble findAny() { - OptionalDouble result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = _findFirst(); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::iterator(DoubleStream) -> PrimitiveIterator_OfDouble - * Source: java/util/stream/DoubleStream.main.lsl:918 - */ - public PrimitiveIterator.OfDouble iterator() { - PrimitiveIterator.OfDouble result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = (stub.java.util.stream.DoubleStreamLSLIterator) ((Object) new DoubleStreamLSLIterator((Void) null, - /* state = */ DoubleStreamLSLIterator.__$lsl_States.Initialized, - /* parent = */ this, - /* cursor = */ 0 - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::spliterator(DoubleStream) -> Spliterator_OfDouble - * Source: java/util/stream/DoubleStream.main.lsl:932 - */ - public Spliterator.OfDouble spliterator() { - Spliterator.OfDouble result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = (Spliterators_DoubleArraySpliterator) ((Object) new generated.java.util.Spliterators_DoubleArraySpliterator((Void) null, - /* state = */ generated.java.util.Spliterators_DoubleArraySpliterator.__$lsl_States.Initialized, - /* array = */ this.storage, - /* index = */ 0, - /* fence = */ this.length, - /* characteristics = */ LibSLGlobals.SPLITERATOR_ORDERED | LibSLGlobals.SPLITERATOR_IMMUTABLE | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::isParallel(DoubleStream) -> boolean - * Source: java/util/stream/DoubleStream.main.lsl:948 - */ - public boolean isParallel() { - boolean result = false; - /* body */ { - result = this.isParallel; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::sequential(DoubleStream) -> DoubleStream - * Source: java/util/stream/DoubleStream.main.lsl:954 - */ - public DoubleStream sequential() { - DoubleStream result = null; - /* body */ { - this.isParallel = false; - result = this; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::parallel(DoubleStream) -> DoubleStream - * Source: java/util/stream/DoubleStream.main.lsl:961 - */ - public DoubleStream parallel() { - DoubleStream result = null; - /* body */ { - this.isParallel = true; - result = this; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::unordered(DoubleStream) -> DoubleStream - * Source: java/util/stream/DoubleStream.main.lsl:968 - */ - public DoubleStream unordered() { - DoubleStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::onClose(DoubleStream, Runnable) -> DoubleStream - * Source: java/util/stream/DoubleStream.main.lsl:981 - */ - public DoubleStream onClose(Runnable closeHandler) { - DoubleStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - final int listLength = this.closeHandlers.size(); - this.closeHandlers.insert(listLength, closeHandler); - result = this; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::close(DoubleStream) -> void - * Source: java/util/stream/DoubleStream.main.lsl:993 - */ - public void close() { - /* body */ { - final int listLength = this.closeHandlers.size(); - int i = 0; - for (i = 0; i < listLength; i += 1) { - final Runnable currentHandler = ((Runnable) this.closeHandlers.get(i)); - currentHandler.run(); - } - ; - this.closeHandlers = Engine.makeSymbolicList(); - this.linkedOrConsumed = true; - } - } - - /** - * [FUNCTION] DoubleStreamAutomaton::dropWhile(DoubleStream, DoublePredicate) -> DoubleStream - * Source: java/util/stream/DoubleStream.main.lsl:1017 - */ - public DoubleStream dropWhile(DoublePredicate predicate) { - DoubleStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - if (this.length == 0) { - final double[] emptyStorage = new double[0]; - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ emptyStorage, - /* length = */ 0, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - Engine.assume(this.length > 0); - int dropLength = 0; - int i = 0; - while ((i < this.length) && predicate.test(storage[i])) { - dropLength += 1; - i += 1; - } - ; - if (dropLength == 0) { - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - final int newLength = this.length - dropLength; - final double[] newStorage = new double[newLength]; - int j = dropLength; - i = dropLength; - while (i < this.length) { - newStorage[j] = storage[i]; - j += 1; - i += 1; - } - ; - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ newStorage, - /* length = */ newLength, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::takeWhile(DoubleStream, DoublePredicate) -> DoubleStream - * Source: java/util/stream/DoubleStream.main.lsl:1092 - */ - public DoubleStream takeWhile(DoublePredicate predicate) { - DoubleStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - if (this.length == 0) { - final double[] emptyStorage = new double[0]; - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ emptyStorage, - /* length = */ 0, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - Engine.assume(this.length > 0); - int takeLength = 0; - int i = 0; - while ((i < this.length) && predicate.test(storage[i])) { - takeLength += 1; - i += 1; - } - ; - if (takeLength == this.length) { - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - final int newLength = takeLength; - final double[] newStorage = new double[newLength]; - int j = 0; - i = 0; - while (i < takeLength) { - newStorage[j] = storage[i]; - j += 1; - i += 1; - } - ; - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ newStorage, - /* length = */ newLength, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::sum(DoubleStream) -> double - * Source: java/util/stream/DoubleStream.main.lsl:1167 - */ - public double sum() { - double result = 0.0d; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = _sum(); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::average(DoubleStream) -> OptionalDouble - * Source: java/util/stream/DoubleStream.main.lsl:1177 - */ - public OptionalDouble average() { - OptionalDouble result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (this.length == 0) { - result = OptionalDouble.empty(); - } else { - double curSum = _sum(); - double divisionResult = curSum / this.length; - result = OptionalDouble.of(divisionResult); - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::summaryStatistics(DoubleStream) -> DoubleSummaryStatistics - * Source: java/util/stream/DoubleStream.main.lsl:1196 - */ - public DoubleSummaryStatistics summaryStatistics() { - DoubleSummaryStatistics result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = new DoubleSummaryStatistics(); - int i = 0; - for (i = 0; i < this.length; i += 1) { - result.accept(storage[i]); - } - ; - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamAutomaton::boxed(DoubleStream) -> Stream - * Source: java/util/stream/DoubleStream.main.lsl:1217 - */ - public Stream boxed() { - Stream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - final Double[] doubleArray = new Double[this.length]; - int i = 0; - for (i = 0; i < this.length; i += 1) { - doubleArray[i] = storage[i]; - } - ; - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ doubleArray, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(DoubleStreamLSL.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/stream/DoubleStreamLSLIterator.java b/approximations/src/main/java/generated/java/util/stream/DoubleStreamLSLIterator.java deleted file mode 100644 index 2dfb3362..00000000 --- a/approximations/src/main/java/generated/java/util/stream/DoubleStreamLSLIterator.java +++ /dev/null @@ -1,169 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/stream/DoubleStream.lsl:39 -// - java/util/stream/DoubleStream.Iterator.lsl:18 -// -package generated.java.util.stream; - -import java.lang.Double; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.UnsupportedOperationException; -import java.lang.Void; -import java.util.NoSuchElementException; -import java.util.PrimitiveIterator; -import java.util.function.Consumer; -import java.util.function.DoubleConsumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * DoubleStreamIteratorAutomaton for DoubleStreamLSLIterator ~> java.util.stream.DoubleStreamLSLIterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.stream.DoubleStreamLSLIterator.class) -public class DoubleStreamLSLIterator implements LibSLRuntime.Automaton, PrimitiveIterator.OfDouble { - static { - Engine.assume(true); - } - - public DoubleStreamLSL parent; - - public int cursor; - - @LibSLRuntime.AutomatonConstructor - public DoubleStreamLSLIterator(Void __$lsl_token, final byte p0, final DoubleStreamLSL p1, - final int p2) { - this.parent = p1; - this.cursor = p2; - } - - @LibSLRuntime.AutomatonConstructor - public DoubleStreamLSLIterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, 0); - } - - /** - * [FUNCTION] DoubleStreamIteratorAutomaton::hasNext(DoubleStreamLSLIterator) -> boolean - * Source: java/util/stream/DoubleStream.Iterator.lsl:41 - */ - public boolean hasNext() { - boolean result = false; - /* body */ { - Engine.assume(this.parent != null); - result = this.cursor != ((DoubleStreamLSL) ((Object) this.parent)).length; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamIteratorAutomaton::next(DoubleStreamLSLIterator) -> Double - * Source: java/util/stream/DoubleStream.Iterator.lsl:50 - */ - public Double next() { - Double result = null; - /* body */ { - Engine.assume(this.parent != null); - final double[] parentStorage = ((DoubleStreamLSL) ((Object) this.parent)).storage; - final int i = this.cursor; - if (i >= ((DoubleStreamLSL) ((Object) this.parent)).length) { - throw new NoSuchElementException(); - } - this.cursor = i + 1; - result = parentStorage[i]; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamIteratorAutomaton::nextDouble(DoubleStreamLSLIterator) -> double - * Source: java/util/stream/DoubleStream.Iterator.lsl:66 - */ - public double nextDouble() { - double result = 0.0d; - /* body */ { - Engine.assume(this.parent != null); - final double[] parentStorage = ((DoubleStreamLSL) ((Object) this.parent)).storage; - final int i = this.cursor; - if (i >= ((DoubleStreamLSL) ((Object) this.parent)).length) { - throw new NoSuchElementException(); - } - this.cursor = i + 1; - result = parentStorage[i]; - } - return result; - } - - /** - * [FUNCTION] DoubleStreamIteratorAutomaton::remove(DoubleStreamLSLIterator) -> void - * Source: java/util/stream/DoubleStream.Iterator.lsl:82 - */ - public void remove() { - /* body */ { - throw new UnsupportedOperationException(); - } - } - - /** - * [FUNCTION] DoubleStreamIteratorAutomaton::forEachRemaining(DoubleStreamLSLIterator, Consumer) -> void - * Source: java/util/stream/DoubleStream.Iterator.lsl:88 - */ - public void forEachRemaining(Consumer userAction) { - /* body */ { - Engine.assume(this.parent != null); - if (userAction == null) { - throw new NullPointerException(); - } - int i = this.cursor; - final int size = ((DoubleStreamLSL) ((Object) this.parent)).length; - if (i != size) { - final double[] pStorage = ((DoubleStreamLSL) ((Object) this.parent)).storage; - while (i < size) { - final double item = pStorage[i]; - userAction.accept(item); - i += 1; - } - ; - this.cursor = i; - } - } - } - - /** - * [FUNCTION] DoubleStreamIteratorAutomaton::forEachRemaining(DoubleStreamLSLIterator, DoubleConsumer) -> void - * Source: java/util/stream/DoubleStream.Iterator.lsl:113 - */ - public void forEachRemaining(DoubleConsumer userAction) { - /* body */ { - Engine.assume(this.parent != null); - if (userAction == null) { - throw new NullPointerException(); - } - int i = this.cursor; - final int size = ((DoubleStreamLSL) ((Object) this.parent)).length; - if (i != size) { - final double[] pStorage = ((DoubleStreamLSL) ((Object) this.parent)).storage; - while (i < size) { - final double item = pStorage[i]; - userAction.accept(item); - i += 1; - } - ; - this.cursor = i; - } - } - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(DoubleStreamLSLIterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/stream/IntStreamImpl.java b/approximations/src/main/java/generated/java/util/stream/IntStreamImpl.java new file mode 100644 index 00000000..04f57a43 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/stream/IntStreamImpl.java @@ -0,0 +1,654 @@ +package generated.java.util.stream; + +import generated.java.util.array.IntArrayIteratorImpl; +import generated.java.util.array.IntArraySpliteratorImpl; +import generated.runtime.LibSLGlobals; +import java.lang.IllegalArgumentException; +import java.lang.Integer; +import java.lang.NullPointerException; +import java.lang.Object; +import java.lang.Runnable; +import java.util.*; +import java.util.function.BiConsumer; +import java.util.function.IntBinaryOperator; +import java.util.function.IntConsumer; +import java.util.function.IntFunction; +import java.util.function.IntPredicate; +import java.util.function.IntToDoubleFunction; +import java.util.function.IntToLongFunction; +import java.util.function.IntUnaryOperator; +import java.util.function.ObjIntConsumer; +import java.util.function.Supplier; +import java.util.stream.IntStream; +import java.util.stream.Stream; +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; +import org.usvm.api.SymbolicList; +import runtime.LibSLRuntime; +import stub.java.util.stream.*; + +@Approximate(IntStreamStub.class) +public class IntStreamImpl extends BaseStreamImpl implements IntStream { + + public int[] storage; + + public IntStreamImpl( + int[] storage, + SymbolicList closeHandlers, + boolean isParallel, + boolean linkedOrConsumed + ) { + super(closeHandlers, isParallel, linkedOrConsumed); + this.storage = storage; + } + + public IntStreamImpl(int[] storage, SymbolicList closeHandlers, boolean isParallel) { + this(storage, closeHandlers, isParallel, false); + } + + public IntStreamImpl(int[] storage, SymbolicList closeHandlers) { + this(storage, closeHandlers, false); + } + + public IntStreamImpl(int[] storage) { + this(storage, Engine.makeSymbolicList()); + } + + private int[] _getStorage() { + int[] storage = this.storage; + Engine.assume(storage != null); + return storage; + } + + protected int _getLength() { + return _getStorage().length; + } + + private IntStreamImpl _copy(int[] storage) { + return new IntStreamImpl(storage, _getCloseHandlers(), isParallel, linkedOrConsumed); + } + + private IntStreamImpl _copy() { + return _copy(_getStorage()); + } + + private void _actionApply(IntConsumer _action) { + if (_action == null) + throw new NullPointerException(); + + int[] storage = _getStorage(); + for (int j : storage) { + _action.accept(j); + } + } + + private OptionalInt _findFirst() { + int[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return OptionalInt.empty(); + + int first = storage[0]; + return OptionalInt.of(first); + } + + private int _sum() { + int[] storage = _getStorage(); + int result = 0; + for (int j : storage) { + result += j; + } + return result; + } + + @NotNull + @SuppressWarnings("ConstantValue") + public IntStreamImpl filter(@NotNull IntPredicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + int[] storage = _getStorage(); + int length = storage.length; + int[] filteredStorage = Arrays.copyOf(storage, length); + int filteredLength = 0; + for (int e : storage) { + if (predicate.test(e)) { + filteredStorage[filteredLength] = e; + filteredLength++; + } + } + + Engine.assume(filteredLength <= length); + int[] resultStorage = Arrays.copyOf(filteredStorage, filteredLength); + return _copy(resultStorage); + } + + @NotNull + @SuppressWarnings("ConstantValue") + public IntStreamImpl map(@NotNull IntUnaryOperator mapper) { + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + int[] storage = _getStorage(); + int length = storage.length; + int[] mappedStorage = new int[length]; + for (int i = 0; i < length; i++) { + mappedStorage[i] = mapper.applyAsInt(storage[i]); + } + + return _copy(mappedStorage); + } + + @NotNull + @SuppressWarnings({"unchecked", "ConstantValue"}) + public StreamStubImpl mapToObj(@NotNull IntFunction mapper) { + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + int[] storage = _getStorage(); + int length = storage.length; + T[] objStorage = (T[]) new Object[length]; + for (int i = 0; i < length; i++) { + objStorage[i] = mapper.apply(storage[i]); + } + + return _copyToObjStream(objStorage); + } + + @NotNull + @SuppressWarnings("ConstantValue") + public LongStreamImpl mapToLong(@NotNull IntToLongFunction mapper) { + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + int[] storage = _getStorage(); + int length = storage.length; + long[] mappedStorage = new long[length]; + for (int i = 0; i < length; i++) { + mappedStorage[i] = mapper.applyAsLong(storage[i]); + } + + return _copyToLongStream(mappedStorage); + } + + @NotNull + @SuppressWarnings("ConstantValue") + public DoubleStreamImpl mapToDouble(@NotNull IntToDoubleFunction mapper) { + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + int[] storage = _getStorage(); + int length = storage.length; + double[] mappedStorage = new double[length]; + for (int i = 0; i < length; i++) { + mappedStorage[i] = mapper.applyAsDouble(storage[i]); + } + + return _copyToDoubleStream(mappedStorage); + } + + @NotNull + @SuppressWarnings({"ConstantValue", "DataFlowIssue"}) + public IntStream flatMap(@NotNull IntFunction mapper) { + // TODO: approximate + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + IntStream result = Engine.makeSymbolic(IntStream.class); + Engine.assume(result != null); + return result; + } + + @NotNull + public IntStreamImpl sorted() { + super.evaluate(); + + int[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return _copy(); + + int outerLimit = length - 1; + for (int i = 0; i < outerLimit; i++) { + int innerLimit = length - i - 1; + for (int j = 0; j < innerLimit; j++) { + int idxB = j + 1; + int a = storage[j]; + int b = storage[idxB]; + if (a > b) { + storage[j] = b; + storage[idxB] = a; + } + } + } + + return _copy(); + } + + @NotNull + public IntStreamImpl distinct() { + super.evaluate(); + + int[] storage = _getStorage(); + int[] distinctStorage; + int length = storage.length; + if (length == 0) { + distinctStorage = Arrays.copyOf(storage, 0); + return _copy(distinctStorage); + } + + int distinctLength = 0; + distinctStorage = Arrays.copyOf(storage, length); + LibSLRuntime.Map visited = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); + for (int item : storage) { + if (!visited.hasKey(item)) { + visited.set(item, LibSLGlobals.SOMETHING); + distinctStorage[distinctLength] = item; + distinctLength++; + } + } + + Engine.assume(distinctLength <= length); + int[] resultStorage = Arrays.copyOf(distinctStorage, distinctLength); + return _copy(resultStorage); + } + + @NotNull + public IntStreamImpl peek(@NotNull IntConsumer _action) { + super.evaluate(); + _actionApply(_action); + return _copy(); + } + + @NotNull + public IntStreamImpl limit(long maxSize) { + super.evaluate(); + + int maxSizeInt = (int) maxSize; + + if (maxSizeInt < 0) + throw new IllegalArgumentException(); + + if (maxSizeInt == 0) + return _copy(Arrays.copyOf(_getStorage(), 0)); + + int[] storage = _getStorage(); + int length = storage.length; + if (maxSizeInt > length) + return _copy(); + + int[] limitStorage = Arrays.copyOf(storage, maxSizeInt); + return _copy(limitStorage); + } + + @NotNull + public IntStreamImpl skip(long n) { + super.evaluate(); + + int offset = (int) n; + + if (offset < 0) + throw new IllegalArgumentException(); + + if (offset == 0) + return _copy(); + + int[] storage = _getStorage(); + int length = storage.length; + if (offset >= length) + return _copy(Arrays.copyOf(_getStorage(), 0)); + + int[] skipStorage = Arrays.copyOfRange(storage, offset, length); + return _copy(skipStorage); + } + + public void forEach(IntConsumer _action) { + super.evaluate(); + _actionApply(_action); + } + + public void forEachOrdered(IntConsumer _action) { + forEach(_action); + } + + public int[] toArray() { + super.evaluate(); + return _getStorage(); + } + + public int reduce(int identity, IntBinaryOperator accumulator) { + super.evaluate(); + + if (accumulator == null) + throw new NullPointerException(); + + int result = identity; + int[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return result; + + for (int item : storage) { + result = accumulator.applyAsInt(result, item); + } + + return result; + } + + public OptionalInt reduce(IntBinaryOperator accumulator) { + super.evaluate(); + + if (accumulator == null) + throw new NullPointerException(); + + int[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return OptionalInt.empty(); + + int value = storage[0]; + for (int i = 1; i < length; i++) { + value = accumulator.applyAsInt(value, storage[i]); + } + + return OptionalInt.of(value); + } + + public R collect(Supplier supplier, ObjIntConsumer accumulator, BiConsumer combiner) { + super.evaluate(); + + if (supplier == null) + throw new NullPointerException(); + + if (accumulator == null) + throw new NullPointerException(); + + if (combiner == null) + throw new NullPointerException(); + + R result = supplier.get(); + int[] storage = _getStorage(); + for (int item : storage) { + accumulator.accept(result, item); + } + + return result; + } + + public OptionalInt min() { + super.evaluate(); + + int[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return OptionalInt.empty(); + + int min = storage[0]; + for (int i = 1; i < length; i++) { + int item = storage[i]; + if (min > item) + min = item; + } + + return OptionalInt.of(min); + } + + public OptionalInt max() { + super.evaluate(); + + int[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return OptionalInt.empty(); + + int max = storage[0]; + for (int i = 1; i < length; i++) { + int item = storage[i]; + if (max < item) + max = item; + } + + return OptionalInt.of(max); + } + + public long count() { + return super.count(); + } + + public boolean anyMatch(IntPredicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + int[] storage = _getStorage(); + for (int item : storage) { + if (predicate.test(item)) + return true; + } + + return false; + } + + public boolean allMatch(IntPredicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + int[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return true; + + for (int item : storage) { + if (!predicate.test(item)) + return false; + } + + return true; + } + + public boolean noneMatch(IntPredicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + int[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return true; + + for (int item : storage) { + if (predicate.test(item)) + return false; + } + + return true; + } + + public OptionalInt findFirst() { + super.evaluate(); + return _findFirst(); + } + + public OptionalInt findAny() { + return findFirst(); + } + + @NotNull + public PrimitiveIterator.OfInt iterator() { + super.evaluate(); + return new IntArrayIteratorImpl(_getStorage()); + } + + @NotNull + public Spliterator.OfInt spliterator() { + super.evaluate(); + int[] storage = _getStorage(); + return new IntArraySpliteratorImpl(storage, spliteratorCharacteristics); + } + + public boolean isParallel() { + return super.isParallel(); + } + + @NotNull + public IntStreamImpl sequential() { + return (IntStreamImpl) super.sequential(); + } + + @NotNull + public IntStreamImpl parallel() { + return (IntStreamImpl) super.parallel(); + } + + @NotNull + public IntStreamImpl unordered() { + super.evaluate(); + return _copy(); + } + + @NotNull + public IntStreamImpl onClose(@NotNull Runnable closeHandler) { + return (IntStreamImpl) super.onClose(closeHandler); + } + + public void close() { + super.close(); + } + + @NotNull + @SuppressWarnings("ConstantValue") + public IntStreamImpl dropWhile(@NotNull IntPredicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + int[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return _copy(Arrays.copyOf(storage, 0)); + + int dropLength = 0; + while (dropLength < length && predicate.test(storage[dropLength])) { + dropLength++; + } + + if (dropLength == 0) + return _copy(); + + int newLength = length - dropLength; + int[] newStorage = Arrays.copyOf(storage, newLength); + return _copy(newStorage); + } + + @NotNull + @SuppressWarnings("ConstantValue") + public IntStreamImpl takeWhile(@NotNull IntPredicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + int[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return _copy(Arrays.copyOf(storage, 0)); + + int takeLength = 0; + while (takeLength < length && predicate.test(storage[takeLength])) { + takeLength++; + } + + if (takeLength == length) + return _copy(); + + int[] newStorage = Arrays.copyOf(storage, takeLength); + return _copy(newStorage); + } + + public LongStreamImpl asLongStream() { + super.evaluate(); + + int[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return _copyToLongStream(new long[0]); + + long[] newStorage = new long[length]; + LibSLRuntime.ArrayActions.copy(storage, 0, newStorage, 0, length); + return _copyToLongStream(newStorage); + } + + public DoubleStreamImpl asDoubleStream() { + super.evaluate(); + + int[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return _copyToDoubleStream(new double[0]); + + double[] newStorage = new double[length]; + LibSLRuntime.ArrayActions.copy(storage, 0, newStorage, 0, length); + return _copyToDoubleStream(newStorage); + } + + public int sum() { + super.evaluate(); + return _sum(); + } + + public OptionalDouble average() { + super.evaluate(); + + int[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return OptionalDouble.empty(); + + double curSum = _sum(); + double divisionResult = curSum / length; + return OptionalDouble.of(divisionResult); + } + + public IntSummaryStatistics summaryStatistics() { + super.evaluate(); + + int[] storage = _getStorage(); + IntSummaryStatistics result = new IntSummaryStatistics(); + for (int j : storage) { + result.accept(j); + } + + return result; + } + + public Stream boxed() { + super.evaluate(); + + int[] storage = _getStorage(); + int length = storage.length; + Integer[] integerArray = new Integer[length]; + for (int i = 0; i < length; i++) { + integerArray[i] = storage[i]; + } + + return _copyToObjStream(integerArray); + } +} diff --git a/approximations/src/main/java/generated/java/util/stream/IntStreamLSL.java b/approximations/src/main/java/generated/java/util/stream/IntStreamLSL.java deleted file mode 100644 index ee52e738..00000000 --- a/approximations/src/main/java/generated/java/util/stream/IntStreamLSL.java +++ /dev/null @@ -1,1337 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/stream/IntStream.lsl:26 -// - java/util/stream/IntStream.main.lsl:27 -// -package generated.java.util.stream; - -import generated.runtime.LibSLGlobals; -import java.lang.IllegalArgumentException; -import java.lang.IllegalStateException; -import java.lang.Integer; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.Runnable; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.IntSummaryStatistics; -import java.util.OptionalDouble; -import java.util.OptionalInt; -import java.util.PrimitiveIterator; -import java.util.Spliterator; -import java.util.function.BiConsumer; -import java.util.function.IntBinaryOperator; -import java.util.function.IntConsumer; -import java.util.function.IntFunction; -import java.util.function.IntPredicate; -import java.util.function.IntToDoubleFunction; -import java.util.function.IntToLongFunction; -import java.util.function.IntUnaryOperator; -import java.util.function.ObjIntConsumer; -import java.util.function.Supplier; -import java.util.stream.DoubleStream; -import java.util.stream.IntStream; -import java.util.stream.LongStream; -import java.util.stream.Stream; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import org.usvm.api.SymbolicList; -import runtime.LibSLRuntime; -import stub.java.util.Spliterators_IntArraySpliterator; - -/** - * IntStreamAutomaton for IntStreamLSL ~> java.util.stream.IntStreamLSL - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.stream.IntStreamLSL.class) -public class IntStreamLSL implements LibSLRuntime.Automaton, IntStream { - static { - Engine.assume(true); - } - - public int[] storage; - - public transient int length; - - public SymbolicList closeHandlers; - - public boolean isParallel; - - public boolean linkedOrConsumed; - - @LibSLRuntime.AutomatonConstructor - public IntStreamLSL(Void __$lsl_token, final byte p0, final int[] p1, final int p2, - final SymbolicList p3, final boolean p4, final boolean p5) { - this.storage = p1; - this.length = p2; - this.closeHandlers = p3; - this.isParallel = p4; - this.linkedOrConsumed = p5; - } - - @LibSLRuntime.AutomatonConstructor - public IntStreamLSL(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, 0, null, false, false); - } - - /** - * [SUBROUTINE] IntStreamAutomaton::_actionApply(IntConsumer) -> void - * Source: java/util/stream/IntStream.main.lsl:117 - */ - private void _actionApply(IntConsumer _action) { - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - int i = 0; - for (i = 0; i < this.length; i += 1) { - _action.accept(storage[i]); - } - ; - } - } - - /** - * [SUBROUTINE] IntStreamAutomaton::_findFirst() -> OptionalInt - * Source: java/util/stream/IntStream.main.lsl:136 - */ - private OptionalInt _findFirst() { - OptionalInt result = null; - /* body */ { - if (this.length == 0) { - result = OptionalInt.empty(); - } else { - final int first = storage[0]; - result = OptionalInt.of(first); - } - } - return result; - } - - /** - * [SUBROUTINE] IntStreamAutomaton::_sum() -> int - * Source: java/util/stream/IntStream.main.lsl:150 - */ - private int _sum() { - int result = 0; - /* body */ { - result = 0; - if (this.length != 0) { - int i = 0; - for (i = 0; i < this.length; i += 1) { - result += storage[i]; - } - ; - } - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::filter(IntStream, IntPredicate) -> IntStream - * Source: java/util/stream/IntStream.main.lsl:172 - */ - public IntStream filter(IntPredicate predicate) { - IntStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - int[] filteredStorage = new int[this.length]; - int filteredLength = 0; - int i = 0; - for (i = 0; i < this.length; i += 1) { - if (predicate.test(storage[i])) { - filteredStorage[filteredLength] = storage[i]; - filteredLength += 1; - } - } - ; - Engine.assume(filteredLength <= this.length); - int[] resultStorage = new int[filteredLength]; - LibSLRuntime.ArrayActions.copy(filteredStorage, 0, resultStorage, 0, filteredLength); - result = (stub.java.util.stream.IntStreamLSL) ((Object) new IntStreamLSL((Void) null, - /* state = */ IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ resultStorage, - /* length = */ filteredLength, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::map(IntStream, IntUnaryOperator) -> IntStream - * Source: java/util/stream/IntStream.main.lsl:213 - */ - public IntStream map(IntUnaryOperator mapper) { - IntStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (mapper == null) { - throw new NullPointerException(); - } - int[] mappedStorage = new int[this.length]; - int i = 0; - for (i = 0; i < this.length; i += 1) { - mappedStorage[i] = mapper.applyAsInt(storage[i]); - } - ; - result = (stub.java.util.stream.IntStreamLSL) ((Object) new IntStreamLSL((Void) null, - /* state = */ IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ mappedStorage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::mapToObj(IntStream, IntFunction) -> Stream - * Source: java/util/stream/IntStream.main.lsl:244 - */ - public Stream mapToObj(IntFunction mapper) { - Stream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - final Object[] objStorage = new Object[this.length]; - int i = 0; - for (i = 0; i < this.length; i += 1) { - objStorage[i] = mapper.apply(storage[i]); - } - ; - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ objStorage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::mapToLong(IntStream, IntToLongFunction) -> LongStream - * Source: java/util/stream/IntStream.main.lsl:273 - */ - public LongStream mapToLong(IntToLongFunction mapper) { - LongStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (mapper == null) { - throw new NullPointerException(); - } - long[] mappedStorage = new long[this.length]; - int i = 0; - for (i = 0; i < this.length; i += 1) { - mappedStorage[i] = mapper.applyAsLong(storage[i]); - } - ; - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ mappedStorage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::mapToDouble(IntStream, IntToDoubleFunction) -> DoubleStream - * Source: java/util/stream/IntStream.main.lsl:304 - */ - public DoubleStream mapToDouble(IntToDoubleFunction mapper) { - DoubleStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (mapper == null) { - throw new NullPointerException(); - } - double[] mappedStorage = new double[this.length]; - int i = 0; - for (i = 0; i < this.length; i += 1) { - mappedStorage[i] = mapper.applyAsDouble(storage[i]); - } - ; - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ mappedStorage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::flatMap(IntStream, IntFunction) -> IntStream - * Source: java/util/stream/IntStream.main.lsl:335 - */ - public IntStream flatMap(IntFunction mapper) { - IntStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (mapper == null) { - throw new NullPointerException(); - } - result = Engine.makeSymbolic(IntStream.class); - Engine.assume(result != null); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::sorted(IntStream) -> IntStream - * Source: java/util/stream/IntStream.main.lsl:351 - */ - public IntStream sorted() { - IntStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (this.length == 0) { - result = (stub.java.util.stream.IntStreamLSL) ((Object) new IntStreamLSL((Void) null, - /* state = */ IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ 0, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - Engine.assume(this.length > 0); - final int outerLimit = this.length - 1; - int innerLimit = 0; - int i = 0; - int j = 0; - for (i = 0; i < outerLimit; i += 1) { - innerLimit = (this.length - i) - 1; - for (j = 0; j < innerLimit; j += 1) { - final int idxA = j; - final int idxB = j + 1; - final int a = storage[idxA]; - final int b = storage[idxB]; - if (a > b) { - storage[idxA] = b; - storage[idxB] = a; - } - } - ; - } - ; - result = (stub.java.util.stream.IntStreamLSL) ((Object) new IntStreamLSL((Void) null, - /* state = */ IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::distinct(IntStream) -> IntStream - * Source: java/util/stream/IntStream.main.lsl:414 - */ - public IntStream distinct() { - IntStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - int[] distinctStorage = null; - int distinctLength = 0; - final int size = this.length; - if (size == 0) { - distinctStorage = new int[0]; - distinctLength = 0; - } else { - final int[] items = this.storage; - Engine.assume(items != null); - Engine.assume(items.length != 0); - Engine.assume(size == items.length); - int i = 0; - int j = 0; - final SymbolicList uniqueItems = Engine.makeSymbolicList(); - final LibSLRuntime.Map visited = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - for (i = 0; i < size; i += 1) { - final int item = items[i]; - if (!visited.hasKey(item)) { - visited.set(item, LibSLGlobals.SOMETHING); - uniqueItems.insert(j, item); - j += 1; - } - } - ; - distinctLength = j; - Engine.assume(distinctLength > 0); - Engine.assume(distinctLength <= size); - distinctStorage = new int[distinctLength]; - for (i = 0; i < distinctLength; i += 1) { - final Integer item = uniqueItems.get(i); - Engine.assume(item != null); - distinctStorage[i] = ((int) item); - } - ; - } - result = (stub.java.util.stream.IntStreamLSL) ((Object) new IntStreamLSL((Void) null, - /* state = */ IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ distinctStorage, - /* length = */ distinctLength, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::peek(IntStream, IntConsumer) -> IntStream - * Source: java/util/stream/IntStream.main.lsl:486 - */ - public IntStream peek(IntConsumer _action) { - IntStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - _actionApply(_action); - result = (stub.java.util.stream.IntStreamLSL) ((Object) new IntStreamLSL((Void) null, - /* state = */ IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::limit(IntStream, long) -> IntStream - * Source: java/util/stream/IntStream.main.lsl:502 - */ - public IntStream limit(long maxSize) { - IntStream result = null; - /* body */ { - final int maxSizeInt = ((int) maxSize); - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (maxSizeInt < 0) { - throw new IllegalArgumentException(); - } - if (maxSizeInt == 0) { - result = (stub.java.util.stream.IntStreamLSL) ((Object) new IntStreamLSL((Void) null, - /* state = */ IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ 0, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - if (maxSizeInt > this.length) { - result = (stub.java.util.stream.IntStreamLSL) ((Object) new IntStreamLSL((Void) null, - /* state = */ IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - final int[] limitStorage = new int[maxSizeInt]; - LibSLRuntime.ArrayActions.copy(this.storage, 0, limitStorage, 0, maxSizeInt); - result = (stub.java.util.stream.IntStreamLSL) ((Object) new IntStreamLSL((Void) null, - /* state = */ IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ limitStorage, - /* length = */ maxSizeInt, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::skip(IntStream, long) -> IntStream - * Source: java/util/stream/IntStream.main.lsl:544 - */ - public IntStream skip(long n) { - IntStream result = null; - /* body */ { - final int offset = ((int) n); - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (offset < 0) { - throw new IllegalArgumentException(); - } - if (offset == 0) { - result = (stub.java.util.stream.IntStreamLSL) ((Object) new IntStreamLSL((Void) null, - /* state = */ IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - if (offset >= this.length) { - int[] newArray = {}; - result = (stub.java.util.stream.IntStreamLSL) ((Object) new IntStreamLSL((Void) null, - /* state = */ IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ newArray, - /* length = */ 0, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - final int newLength = this.length - offset; - final int[] skipStorage = new int[newLength]; - int i = 0; - int skipIndex = 0; - for (i = offset; i < this.length; i += 1) { - skipStorage[skipIndex] = storage[i]; - skipIndex += 1; - } - ; - result = (stub.java.util.stream.IntStreamLSL) ((Object) new IntStreamLSL((Void) null, - /* state = */ IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ skipStorage, - /* length = */ newLength, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::forEach(IntStream, IntConsumer) -> void - * Source: java/util/stream/IntStream.main.lsl:599 - */ - public void forEach(IntConsumer _action) { - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - _actionApply(_action); - this.linkedOrConsumed = true; - } - } - - /** - * [FUNCTION] IntStreamAutomaton::forEachOrdered(IntStream, IntConsumer) -> void - * Source: java/util/stream/IntStream.main.lsl:608 - */ - public void forEachOrdered(IntConsumer _action) { - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - _actionApply(_action); - this.linkedOrConsumed = true; - } - } - - /** - * [FUNCTION] IntStreamAutomaton::toArray(IntStream) -> array - * Source: java/util/stream/IntStream.main.lsl:617 - */ - public int[] toArray() { - int[] result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = this.storage; - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::reduce(IntStream, int, IntBinaryOperator) -> int - * Source: java/util/stream/IntStream.main.lsl:626 - */ - public int reduce(int identity, IntBinaryOperator accumulator) { - int result = 0; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (accumulator == null) { - throw new NullPointerException(); - } - result = identity; - if (this.length != 0) { - Engine.assume(this.length > 0); - int i = 0; - for (i = 0; i < this.length; i += 1) { - result = accumulator.applyAsInt(result, storage[i]); - } - ; - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::reduce(IntStream, IntBinaryOperator) -> OptionalInt - * Source: java/util/stream/IntStream.main.lsl:655 - */ - public OptionalInt reduce(IntBinaryOperator accumulator) { - OptionalInt result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (accumulator == null) { - throw new NullPointerException(); - } - if (this.length == 0) { - result = OptionalInt.empty(); - } else { - if (this.length > 0) { - int value = storage[0]; - int i = 0; - for (i = 1; i < this.length; i += 1) { - value = accumulator.applyAsInt(value, storage[i]); - } - ; - result = OptionalInt.of(value); - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::collect(IntStream, Supplier, ObjIntConsumer, BiConsumer) -> Object - * Source: java/util/stream/IntStream.main.lsl:689 - */ - public Object collect(Supplier supplier, ObjIntConsumer accumulator, BiConsumer combiner) { - Object result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (supplier == null) { - throw new NullPointerException(); - } - if (accumulator == null) { - throw new NullPointerException(); - } - if (combiner == null) { - throw new NullPointerException(); - } - result = supplier.get(); - int i = 0; - for (i = 0; i < this.length; i += 1) { - accumulator.accept(result, storage[i]); - } - ; - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::min(IntStream) -> OptionalInt - * Source: java/util/stream/IntStream.main.lsl:721 - */ - public OptionalInt min() { - OptionalInt result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (this.length == 0) { - result = OptionalInt.empty(); - } else { - int min = storage[0]; - int i = 0; - for (i = 1; i < this.length; i += 1) { - if (min > storage[i]) { - min = storage[i]; - } - } - ; - result = OptionalInt.of(min); - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::max(IntStream) -> OptionalInt - * Source: java/util/stream/IntStream.main.lsl:753 - */ - public OptionalInt max() { - OptionalInt result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (this.length == 0) { - result = OptionalInt.empty(); - } else { - int max = storage[0]; - int i = 0; - for (i = 1; i < this.length; i += 1) { - if (max < storage[i]) { - max = storage[i]; - } - } - ; - result = OptionalInt.of(max); - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::count(IntStream) -> long - * Source: java/util/stream/IntStream.main.lsl:785 - */ - public long count() { - long result = 0L; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = this.length; - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::anyMatch(IntStream, IntPredicate) -> boolean - * Source: java/util/stream/IntStream.main.lsl:794 - */ - public boolean anyMatch(IntPredicate predicate) { - boolean result = false; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - result = false; - int i = 0; - while ((i < this.length) && !predicate.test(storage[i])) { - i += 1; - } - ; - if (i < this.length) { - result = true; - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::allMatch(IntStream, IntPredicate) -> boolean - * Source: java/util/stream/IntStream.main.lsl:822 - */ - public boolean allMatch(IntPredicate predicate) { - boolean result = false; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - result = true; - if (this.length > 0) { - result = false; - int i = 0; - while ((i < this.length) && predicate.test(storage[i])) { - i += 1; - } - ; - if (i == this.length) { - result = true; - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::noneMatch(IntStream, IntPredicate) -> boolean - * Source: java/util/stream/IntStream.main.lsl:848 - */ - public boolean noneMatch(IntPredicate predicate) { - boolean result = false; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - result = true; - if (this.length > 0) { - result = false; - int i = 0; - while ((i < this.length) && !predicate.test(storage[i])) { - i += 1; - } - ; - if (i == this.length) { - result = true; - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::findFirst(IntStream) -> OptionalInt - * Source: java/util/stream/IntStream.main.lsl:874 - */ - public OptionalInt findFirst() { - OptionalInt result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = _findFirst(); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::findAny(IntStream) -> OptionalInt - * Source: java/util/stream/IntStream.main.lsl:883 - */ - public OptionalInt findAny() { - OptionalInt result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = _findFirst(); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::iterator(IntStream) -> PrimitiveIterator_OfInt - * Source: java/util/stream/IntStream.main.lsl:892 - */ - public PrimitiveIterator.OfInt iterator() { - PrimitiveIterator.OfInt result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = (stub.java.util.stream.IntStreamLSLIterator) ((Object) new IntStreamLSLIterator((Void) null, - /* state = */ IntStreamLSLIterator.__$lsl_States.Initialized, - /* parent = */ this, - /* cursor = */ 0 - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::spliterator(IntStream) -> Spliterator_OfInt - * Source: java/util/stream/IntStream.main.lsl:906 - */ - public Spliterator.OfInt spliterator() { - Spliterator.OfInt result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = (Spliterators_IntArraySpliterator) ((Object) new generated.java.util.Spliterators_IntArraySpliterator((Void) null, - /* state = */ generated.java.util.Spliterators_IntArraySpliterator.__$lsl_States.Initialized, - /* array = */ this.storage, - /* index = */ 0, - /* fence = */ this.length, - /* characteristics = */ LibSLGlobals.SPLITERATOR_ORDERED | LibSLGlobals.SPLITERATOR_IMMUTABLE | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::isParallel(IntStream) -> boolean - * Source: java/util/stream/IntStream.main.lsl:922 - */ - public boolean isParallel() { - boolean result = false; - /* body */ { - result = this.isParallel; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::sequential(IntStream) -> IntStream - * Source: java/util/stream/IntStream.main.lsl:928 - */ - public IntStream sequential() { - IntStream result = null; - /* body */ { - this.isParallel = false; - result = this; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::parallel(IntStream) -> IntStream - * Source: java/util/stream/IntStream.main.lsl:935 - */ - public IntStream parallel() { - IntStream result = null; - /* body */ { - this.isParallel = true; - result = this; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::unordered(IntStream) -> IntStream - * Source: java/util/stream/IntStream.main.lsl:942 - */ - public IntStream unordered() { - IntStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = (stub.java.util.stream.IntStreamLSL) ((Object) new IntStreamLSL((Void) null, - /* state = */ IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::onClose(IntStream, Runnable) -> IntStream - * Source: java/util/stream/IntStream.main.lsl:955 - */ - public IntStream onClose(Runnable closeHandler) { - IntStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - final int listLength = this.closeHandlers.size(); - this.closeHandlers.insert(listLength, closeHandler); - result = this; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::close(IntStream) -> void - * Source: java/util/stream/IntStream.main.lsl:967 - */ - public void close() { - /* body */ { - final int listLength = this.closeHandlers.size(); - int i = 0; - for (i = 0; i < listLength; i += 1) { - final Runnable currentHandler = ((Runnable) this.closeHandlers.get(i)); - currentHandler.run(); - } - ; - this.closeHandlers = Engine.makeSymbolicList(); - this.linkedOrConsumed = true; - } - } - - /** - * [FUNCTION] IntStreamAutomaton::dropWhile(IntStream, IntPredicate) -> IntStream - * Source: java/util/stream/IntStream.main.lsl:991 - */ - public IntStream dropWhile(IntPredicate predicate) { - IntStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - if (this.length == 0) { - final int[] emptyStorage = new int[0]; - result = (stub.java.util.stream.IntStreamLSL) ((Object) new IntStreamLSL((Void) null, - /* state = */ IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ emptyStorage, - /* length = */ 0, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - Engine.assume(this.length > 0); - int dropLength = 0; - int i = 0; - while ((i < this.length) && predicate.test(storage[i])) { - dropLength += 1; - i += 1; - } - ; - if (dropLength == 0) { - result = (stub.java.util.stream.IntStreamLSL) ((Object) new IntStreamLSL((Void) null, - /* state = */ IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - final int newLength = this.length - dropLength; - final int[] newStorage = new int[newLength]; - int j = dropLength; - i = dropLength; - while (i < this.length) { - newStorage[j] = storage[i]; - j += 1; - i += 1; - } - ; - result = (stub.java.util.stream.IntStreamLSL) ((Object) new IntStreamLSL((Void) null, - /* state = */ IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ newStorage, - /* length = */ newLength, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::takeWhile(IntStream, IntPredicate) -> IntStream - * Source: java/util/stream/IntStream.main.lsl:1066 - */ - public IntStream takeWhile(IntPredicate predicate) { - IntStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - if (this.length == 0) { - final int[] emptyStorage = new int[0]; - result = (stub.java.util.stream.IntStreamLSL) ((Object) new IntStreamLSL((Void) null, - /* state = */ IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ emptyStorage, - /* length = */ 0, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - Engine.assume(this.length > 0); - int takeLength = 0; - int i = 0; - while ((i < this.length) && predicate.test(storage[i])) { - takeLength += 1; - i += 1; - } - ; - if (takeLength == this.length) { - result = (stub.java.util.stream.IntStreamLSL) ((Object) new IntStreamLSL((Void) null, - /* state = */ IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - final int newLength = takeLength; - final int[] newStorage = new int[newLength]; - int j = 0; - i = 0; - while (i < takeLength) { - newStorage[j] = storage[i]; - j += 1; - i += 1; - } - ; - result = (stub.java.util.stream.IntStreamLSL) ((Object) new IntStreamLSL((Void) null, - /* state = */ IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ newStorage, - /* length = */ newLength, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::asLongStream(IntStream) -> LongStream - * Source: java/util/stream/IntStream.main.lsl:1141 - */ - public LongStream asLongStream() { - LongStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (this.length == 0) { - final long[] emptyArray = {}; - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ emptyArray, - /* length = */ 0, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - Engine.assume(this.length > 0); - final long[] newStorage = new long[this.length]; - int i = 0; - for (i = 0; i < this.length; i += 1) { - newStorage[i] = ((long) storage[i]); - } - ; - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ newStorage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::asDoubleStream(IntStream) -> DoubleStream - * Source: java/util/stream/IntStream.main.lsl:1183 - */ - public DoubleStream asDoubleStream() { - DoubleStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (this.length == 0) { - final double[] emptyArray = {}; - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ emptyArray, - /* length = */ 0, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - Engine.assume(this.length > 0); - final double[] newStorage = new double[this.length]; - int i = 0; - for (i = 0; i < this.length; i += 1) { - newStorage[i] = ((double) storage[i]); - } - ; - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ newStorage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::sum(IntStream) -> int - * Source: java/util/stream/IntStream.main.lsl:1225 - */ - public int sum() { - int result = 0; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = _sum(); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::average(IntStream) -> OptionalDouble - * Source: java/util/stream/IntStream.main.lsl:1235 - */ - public OptionalDouble average() { - OptionalDouble result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (this.length == 0) { - result = OptionalDouble.empty(); - } else { - double curSum = _sum(); - double divisionResult = curSum / this.length; - result = OptionalDouble.of(divisionResult); - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::summaryStatistics(IntStream) -> IntSummaryStatistics - * Source: java/util/stream/IntStream.main.lsl:1254 - */ - public IntSummaryStatistics summaryStatistics() { - IntSummaryStatistics result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = new IntSummaryStatistics(); - int i = 0; - for (i = 0; i < this.length; i += 1) { - result.accept(storage[i]); - } - ; - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] IntStreamAutomaton::boxed(IntStream) -> Stream - * Source: java/util/stream/IntStream.main.lsl:1275 - */ - public Stream boxed() { - Stream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - final Integer[] integerArray = new Integer[this.length]; - int i = 0; - for (i = 0; i < this.length; i += 1) { - integerArray[i] = storage[i]; - } - ; - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ integerArray, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(IntStreamLSL.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/stream/IntStreamLSLIterator.java b/approximations/src/main/java/generated/java/util/stream/IntStreamLSLIterator.java deleted file mode 100644 index 7b2f7507..00000000 --- a/approximations/src/main/java/generated/java/util/stream/IntStreamLSLIterator.java +++ /dev/null @@ -1,169 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/stream/IntStream.lsl:35 -// - java/util/stream/IntStream.Iterator.lsl:18 -// -package generated.java.util.stream; - -import java.lang.Integer; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.UnsupportedOperationException; -import java.lang.Void; -import java.util.NoSuchElementException; -import java.util.PrimitiveIterator; -import java.util.function.Consumer; -import java.util.function.IntConsumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * IntStreamIteratorAutomaton for IntStreamLSLIterator ~> java.util.stream.IntStreamLSLIterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.stream.IntStreamLSLIterator.class) -public class IntStreamLSLIterator implements LibSLRuntime.Automaton, PrimitiveIterator.OfInt { - static { - Engine.assume(true); - } - - public IntStreamLSL parent; - - public int cursor; - - @LibSLRuntime.AutomatonConstructor - public IntStreamLSLIterator(Void __$lsl_token, final byte p0, final IntStreamLSL p1, - final int p2) { - this.parent = p1; - this.cursor = p2; - } - - @LibSLRuntime.AutomatonConstructor - public IntStreamLSLIterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, 0); - } - - /** - * [FUNCTION] IntStreamIteratorAutomaton::hasNext(IntStreamLSLIterator) -> boolean - * Source: java/util/stream/IntStream.Iterator.lsl:41 - */ - public boolean hasNext() { - boolean result = false; - /* body */ { - Engine.assume(this.parent != null); - result = this.cursor != ((IntStreamLSL) ((Object) this.parent)).length; - } - return result; - } - - /** - * [FUNCTION] IntStreamIteratorAutomaton::next(IntStreamLSLIterator) -> Integer - * Source: java/util/stream/IntStream.Iterator.lsl:50 - */ - public Integer next() { - Integer result = null; - /* body */ { - Engine.assume(this.parent != null); - final int[] parentStorage = ((IntStreamLSL) ((Object) this.parent)).storage; - final int i = this.cursor; - if (i >= ((IntStreamLSL) ((Object) this.parent)).length) { - throw new NoSuchElementException(); - } - this.cursor = i + 1; - result = parentStorage[i]; - } - return result; - } - - /** - * [FUNCTION] IntStreamIteratorAutomaton::nextInt(IntStreamLSLIterator) -> int - * Source: java/util/stream/IntStream.Iterator.lsl:66 - */ - public int nextInt() { - int result = 0; - /* body */ { - Engine.assume(this.parent != null); - final int[] parentStorage = ((IntStreamLSL) ((Object) this.parent)).storage; - final int i = this.cursor; - if (i >= ((IntStreamLSL) ((Object) this.parent)).length) { - throw new NoSuchElementException(); - } - this.cursor = i + 1; - result = parentStorage[i]; - } - return result; - } - - /** - * [FUNCTION] IntStreamIteratorAutomaton::remove(IntStreamLSLIterator) -> void - * Source: java/util/stream/IntStream.Iterator.lsl:82 - */ - public void remove() { - /* body */ { - throw new UnsupportedOperationException(); - } - } - - /** - * [FUNCTION] IntStreamIteratorAutomaton::forEachRemaining(IntStreamLSLIterator, Consumer) -> void - * Source: java/util/stream/IntStream.Iterator.lsl:88 - */ - public void forEachRemaining(Consumer userAction) { - /* body */ { - Engine.assume(this.parent != null); - if (userAction == null) { - throw new NullPointerException(); - } - int i = this.cursor; - final int size = ((IntStreamLSL) ((Object) this.parent)).length; - if (i != size) { - final int[] pStorage = ((IntStreamLSL) ((Object) this.parent)).storage; - while (i < size) { - final int item = pStorage[i]; - userAction.accept(item); - i += 1; - } - ; - this.cursor = i; - } - } - } - - /** - * [FUNCTION] IntStreamIteratorAutomaton::forEachRemaining(IntStreamLSLIterator, IntConsumer) -> void - * Source: java/util/stream/IntStream.Iterator.lsl:113 - */ - public void forEachRemaining(IntConsumer userAction) { - /* body */ { - Engine.assume(this.parent != null); - if (userAction == null) { - throw new NullPointerException(); - } - int i = this.cursor; - final int size = ((IntStreamLSL) ((Object) this.parent)).length; - if (i != size) { - final int[] pStorage = ((IntStreamLSL) ((Object) this.parent)).storage; - while (i < size) { - final int item = pStorage[i]; - userAction.accept(item); - i += 1; - } - ; - this.cursor = i; - } - } - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(IntStreamLSLIterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/stream/LongStreamImpl.java b/approximations/src/main/java/generated/java/util/stream/LongStreamImpl.java new file mode 100644 index 00000000..b7ba0843 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/stream/LongStreamImpl.java @@ -0,0 +1,646 @@ +package generated.java.util.stream; + +import generated.java.util.array.LongArrayIteratorImpl; +import generated.java.util.array.LongArraySpliteratorImpl; +import generated.runtime.LibSLGlobals; +import java.lang.IllegalArgumentException; +import java.lang.Long; +import java.lang.NullPointerException; +import java.lang.Object; +import java.lang.Runnable; +import java.util.*; +import java.util.function.BiConsumer; +import java.util.function.LongBinaryOperator; +import java.util.function.LongConsumer; +import java.util.function.LongFunction; +import java.util.function.LongPredicate; +import java.util.function.LongToDoubleFunction; +import java.util.function.LongToIntFunction; +import java.util.function.LongUnaryOperator; +import java.util.function.ObjLongConsumer; +import java.util.function.Supplier; +import java.util.stream.LongStream; +import java.util.stream.Stream; +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; +import org.usvm.api.SymbolicList; +import runtime.LibSLRuntime; +import stub.java.util.stream.*; + +@Approximate(LongStreamStub.class) +public class LongStreamImpl extends BaseStreamImpl implements LongStream { + + public long[] storage; + + public LongStreamImpl( + long[] storage, + SymbolicList closeHandlers, + boolean isParallel, + boolean linkedOrConsumed + ) { + super(closeHandlers, isParallel, linkedOrConsumed); + this.storage = storage; + } + + public LongStreamImpl(long[] storage, SymbolicList closeHandlers, boolean isParallel) { + this(storage, closeHandlers, isParallel, false); + } + + public LongStreamImpl(long[] storage, SymbolicList closeHandlers) { + this(storage, closeHandlers, false); + } + + public LongStreamImpl(long[] storage) { + this(storage, Engine.makeSymbolicList()); + } + + private long[] _getStorage() { + long[] storage = this.storage; + Engine.assume(storage != null); + return storage; + } + + protected int _getLength() { + return _getStorage().length; + } + + private LongStreamImpl _copy(long[] storage) { + return new LongStreamImpl(storage, _getCloseHandlers(), isParallel, linkedOrConsumed); + } + + private LongStreamImpl _copy() { + return _copy(_getStorage()); + } + + private void _actionApply(LongConsumer _action) { + if (_action == null) + throw new NullPointerException(); + + long[] storage = _getStorage(); + for (long j : storage) { + _action.accept(j); + } + } + + private OptionalLong _findFirst() { + long[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return OptionalLong.empty(); + + long first = storage[0]; + return OptionalLong.of(first); + } + + private long _sum() { + long[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return 0; + + long result = 0; + for (long l : storage) { + result += l; + } + + return result; + } + + @NotNull + @SuppressWarnings("ConstantValue") + public LongStreamImpl filter(@NotNull LongPredicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + long[] storage = _getStorage(); + int length = storage.length; + long[] filteredStorage = Arrays.copyOf(storage, length); + int filteredLength = 0; + for (long e : storage) { + if (predicate.test(e)) { + filteredStorage[filteredLength] = e; + filteredLength++; + } + } + + Engine.assume(filteredLength <= length); + long[] resultStorage = Arrays.copyOf(filteredStorage, filteredLength); + return _copy(resultStorage); + } + + @NotNull + @SuppressWarnings("ConstantValue") + public LongStreamImpl map(@NotNull LongUnaryOperator mapper) { + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + long[] storage = _getStorage(); + int length = storage.length; + long[] mappedStorage = new long[length]; + for (int i = 0; i < length; i++) { + mappedStorage[i] = mapper.applyAsLong(storage[i]); + } + + return _copy(mappedStorage); + } + + @NotNull + @SuppressWarnings({"unchecked", "ConstantValue"}) + public StreamStubImpl mapToObj(@NotNull LongFunction mapper) { + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + long[] storage = _getStorage(); + int length = storage.length; + T[] objStorage = (T[]) new Object[length]; + for (int i = 0; i < length; i++) { + objStorage[i] = mapper.apply(storage[i]); + } + + return _copyToObjStream(objStorage); + } + + @NotNull + @SuppressWarnings("ConstantValue") + public IntStreamImpl mapToInt(@NotNull LongToIntFunction mapper) { + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + long[] storage = _getStorage(); + int length = storage.length; + int[] mappedStorage = new int[length]; + for (int i = 0; i < length; i++) { + mappedStorage[i] = mapper.applyAsInt(storage[i]); + } + + return _copyToIntStream(mappedStorage); + } + + @NotNull + @SuppressWarnings("ConstantValue") + public DoubleStreamImpl mapToDouble(@NotNull LongToDoubleFunction mapper) { + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + long[] storage = _getStorage(); + int length = storage.length; + double[] mappedStorage = new double[length]; + for (int i = 0; i < length; i++) { + mappedStorage[i] = mapper.applyAsDouble(storage[i]); + } + + return _copyToDoubleStream(mappedStorage); + } + + @NotNull + @SuppressWarnings({"ConstantValue", "DataFlowIssue"}) + public LongStream flatMap(@NotNull LongFunction mapper) { + // TODO: approximate + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + LongStream result = Engine.makeSymbolic(LongStream.class); + Engine.assume(result != null); + return result; + } + + @NotNull + public LongStreamImpl sorted() { + super.evaluate(); + + long[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return _copy(); + + int outerLimit = length - 1; + for (int i = 0; i < outerLimit; i++) { + int innerLimit = length - i - 1; + for (int j = 0; j < innerLimit; j++) { + int idxB = j + 1; + long a = storage[j]; + long b = storage[idxB]; + if (a > b) { + storage[j] = b; + storage[idxB] = a; + } + } + } + + return _copy(); + } + + @NotNull + public LongStreamImpl distinct() { + super.evaluate(); + + long[] storage = _getStorage(); + long[] distinctStorage; + int length = storage.length; + if (length == 0) { + distinctStorage = Arrays.copyOf(storage, 0); + return _copy(distinctStorage); + } + + int distinctLength = 0; + distinctStorage = Arrays.copyOf(storage, length); + LibSLRuntime.Map visited = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); + for (long item : storage) { + if (!visited.hasKey(item)) { + visited.set(item, LibSLGlobals.SOMETHING); + distinctStorage[distinctLength] = item; + distinctLength++; + } + } + + Engine.assume(distinctLength <= length); + long[] resultStorage = Arrays.copyOf(distinctStorage, distinctLength); + return _copy(resultStorage); + } + + @NotNull + public LongStreamImpl peek(@NotNull LongConsumer _action) { + super.evaluate(); + _actionApply(_action); + return _copy(); + } + + @NotNull + public LongStreamImpl limit(long maxSize) { + super.evaluate(); + + int maxSizeInt = (int) maxSize; + + if (maxSizeInt < 0) + throw new IllegalArgumentException(); + + if (maxSizeInt == 0) + return _copy(Arrays.copyOf(_getStorage(), 0)); + + long[] storage = _getStorage(); + int length = storage.length; + if (maxSizeInt > length) + return _copy(); + + long[] limitStorage = Arrays.copyOf(storage, maxSizeInt); + return _copy(limitStorage); + } + + @NotNull + public LongStreamImpl skip(long n) { + super.evaluate(); + + int offset = (int) n; + + if (offset < 0) + throw new IllegalArgumentException(); + + if (offset == 0) + return _copy(); + + long[] storage = _getStorage(); + int length = storage.length; + if (offset >= length) + return _copy(Arrays.copyOf(_getStorage(), 0)); + + long[] skipStorage = Arrays.copyOfRange(storage, offset, length); + return _copy(skipStorage); + } + + public void forEach(LongConsumer _action) { + super.evaluate(); + _actionApply(_action); + } + + public void forEachOrdered(LongConsumer _action) { + forEach(_action); + } + + public long[] toArray() { + super.evaluate(); + return _getStorage(); + } + + public long reduce(long identity, LongBinaryOperator accumulator) { + super.evaluate(); + + if (accumulator == null) + throw new NullPointerException(); + + long result = identity; + long[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return result; + + for (long item : storage) { + result = accumulator.applyAsLong(result, item); + } + + return result; + } + + public OptionalLong reduce(LongBinaryOperator accumulator) { + super.evaluate(); + + if (accumulator == null) + throw new NullPointerException(); + + long[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return OptionalLong.empty(); + + long value = storage[0]; + for (int i = 1; i < length; i++) { + value = accumulator.applyAsLong(value, storage[i]); + } + + return OptionalLong.of(value); + } + + public R collect(Supplier supplier, ObjLongConsumer accumulator, BiConsumer combiner) { + super.evaluate(); + + if (supplier == null) + throw new NullPointerException(); + + if (accumulator == null) + throw new NullPointerException(); + + if (combiner == null) + throw new NullPointerException(); + + R result = supplier.get(); + long[] storage = _getStorage(); + for (long item : storage) { + accumulator.accept(result, item); + } + + return result; + } + + public OptionalLong min() { + super.evaluate(); + + long[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return OptionalLong.empty(); + + long min = storage[0]; + for (int i = 1; i < length; i++) { + long item = storage[i]; + if (min > item) + min = item; + } + + return OptionalLong.of(min); + } + + public OptionalLong max() { + super.evaluate(); + + long[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return OptionalLong.empty(); + + long max = storage[0]; + for (int i = 1; i < length; i++) { + long item = storage[i]; + if (max < item) + max = item; + } + + return OptionalLong.of(max); + } + + public long count() { + return super.count(); + } + + public boolean anyMatch(LongPredicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + long[] storage = _getStorage(); + for (long item : storage) { + if (predicate.test(item)) + return true; + } + + return false; + } + + public boolean allMatch(LongPredicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + long[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return true; + + for (long item : storage) { + if (!predicate.test(item)) + return false; + } + + return true; + } + + public boolean noneMatch(LongPredicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + long[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return true; + + for (long item : storage) { + if (predicate.test(item)) + return false; + } + + return true; + } + + public OptionalLong findFirst() { + super.evaluate(); + return _findFirst(); + } + + public OptionalLong findAny() { + return findFirst(); + } + + @NotNull + public PrimitiveIterator.OfLong iterator() { + super.evaluate(); + return new LongArrayIteratorImpl(_getStorage()); + } + + @NotNull + public Spliterator.OfLong spliterator() { + super.evaluate(); + long[] storage = _getStorage(); + return new LongArraySpliteratorImpl(storage, spliteratorCharacteristics); + } + + public boolean isParallel() { + return super.isParallel(); + } + + @NotNull + public LongStreamImpl sequential() { + return (LongStreamImpl) super.sequential(); + } + + @NotNull + public LongStreamImpl parallel() { + return (LongStreamImpl) super.parallel(); + } + + @NotNull + public LongStreamImpl unordered() { + super.evaluate(); + return _copy(); + } + + @NotNull + public LongStreamImpl onClose(@NotNull Runnable closeHandler) { + return (LongStreamImpl) super.onClose(closeHandler); + } + + public void close() { + super.close(); + } + + @NotNull + @SuppressWarnings("ConstantValue") + public LongStreamImpl dropWhile(@NotNull LongPredicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + long[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return _copy(Arrays.copyOf(storage, 0)); + + int dropLength = 0; + while (dropLength < length && predicate.test(storage[dropLength])) { + dropLength++; + } + + if (dropLength == 0) + return _copy(); + + int newLength = length - dropLength; + long[] newStorage = Arrays.copyOf(storage, newLength); + return _copy(newStorage); + } + + @NotNull + @SuppressWarnings("ConstantValue") + public LongStreamImpl takeWhile(@NotNull LongPredicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + long[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return _copy(Arrays.copyOf(storage, 0)); + + int takeLength = 0; + while (takeLength < length && predicate.test(storage[takeLength])) { + takeLength++; + } + + if (takeLength == length) + return _copy(); + + long[] newStorage = Arrays.copyOf(storage, takeLength); + return _copy(newStorage); + } + + public DoubleStreamImpl asDoubleStream() { + super.evaluate(); + + long[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return _copyToDoubleStream(new double[0]); + + double[] newStorage = new double[length]; + LibSLRuntime.ArrayActions.copy(storage, 0, newStorage, 0, length); + return _copyToDoubleStream(newStorage); + } + + public long sum() { + super.evaluate(); + return _sum(); + } + + public OptionalDouble average() { + super.evaluate(); + + long[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return OptionalDouble.empty(); + + double curSum = _sum(); + double divisionResult = curSum / length; + return OptionalDouble.of(divisionResult); + } + + public LongSummaryStatistics summaryStatistics() { + super.evaluate(); + + long[] storage = _getStorage(); + LongSummaryStatistics result = new LongSummaryStatistics(); + for (long j : storage) { + result.accept(j); + } + + return result; + } + + public Stream boxed() { + super.evaluate(); + + long[] storage = _getStorage(); + int length = storage.length; + Long[] integerArray = new Long[length]; + for (int i = 0; i < length; i++) { + integerArray[i] = storage[i]; + } + + return _copyToObjStream(integerArray); + } +} diff --git a/approximations/src/main/java/generated/java/util/stream/LongStreamLSL.java b/approximations/src/main/java/generated/java/util/stream/LongStreamLSL.java deleted file mode 100644 index 10493de8..00000000 --- a/approximations/src/main/java/generated/java/util/stream/LongStreamLSL.java +++ /dev/null @@ -1,1295 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/stream/LongStream.lsl:26 -// - java/util/stream/LongStream.main.lsl:28 -// -package generated.java.util.stream; - -import generated.runtime.LibSLGlobals; -import java.lang.IllegalArgumentException; -import java.lang.IllegalStateException; -import java.lang.Long; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.Runnable; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.LongSummaryStatistics; -import java.util.OptionalDouble; -import java.util.OptionalLong; -import java.util.PrimitiveIterator; -import java.util.Spliterator; -import java.util.function.BiConsumer; -import java.util.function.LongBinaryOperator; -import java.util.function.LongConsumer; -import java.util.function.LongFunction; -import java.util.function.LongPredicate; -import java.util.function.LongToDoubleFunction; -import java.util.function.LongToIntFunction; -import java.util.function.LongUnaryOperator; -import java.util.function.ObjLongConsumer; -import java.util.function.Supplier; -import java.util.stream.DoubleStream; -import java.util.stream.IntStream; -import java.util.stream.LongStream; -import java.util.stream.Stream; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import org.usvm.api.SymbolicList; -import runtime.LibSLRuntime; -import stub.java.util.Spliterators_LongArraySpliterator; - -/** - * LongStreamAutomaton for LongStreamLSL ~> java.util.stream.LongStreamLSL - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.stream.LongStreamLSL.class) -public class LongStreamLSL implements LibSLRuntime.Automaton, LongStream { - static { - Engine.assume(true); - } - - public long[] storage; - - public transient int length; - - public SymbolicList closeHandlers; - - public boolean isParallel; - - public boolean linkedOrConsumed; - - @LibSLRuntime.AutomatonConstructor - public LongStreamLSL(Void __$lsl_token, final byte p0, final long[] p1, final int p2, - final SymbolicList p3, final boolean p4, final boolean p5) { - this.storage = p1; - this.length = p2; - this.closeHandlers = p3; - this.isParallel = p4; - this.linkedOrConsumed = p5; - } - - @LibSLRuntime.AutomatonConstructor - public LongStreamLSL(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, 0, null, false, false); - } - - /** - * [SUBROUTINE] LongStreamAutomaton::_actionApply(LongConsumer) -> void - * Source: java/util/stream/LongStream.main.lsl:117 - */ - private void _actionApply(LongConsumer _action) { - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - int i = 0; - for (i = 0; i < this.length; i += 1) { - _action.accept(storage[i]); - } - ; - } - } - - /** - * [SUBROUTINE] LongStreamAutomaton::_findFirst() -> OptionalLong - * Source: java/util/stream/LongStream.main.lsl:136 - */ - private OptionalLong _findFirst() { - OptionalLong result = null; - /* body */ { - if (this.length == 0) { - result = OptionalLong.empty(); - } else { - final long first = storage[0]; - result = OptionalLong.of(first); - } - } - return result; - } - - /** - * [SUBROUTINE] LongStreamAutomaton::_sum() -> long - * Source: java/util/stream/LongStream.main.lsl:150 - */ - private long _sum() { - long result = 0L; - /* body */ { - result = 0; - if (this.length != 0) { - int i = 0; - for (i = 0; i < this.length; i += 1) { - result += storage[i]; - } - ; - } - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::filter(LongStream, LongPredicate) -> LongStream - * Source: java/util/stream/LongStream.main.lsl:172 - */ - public LongStream filter(LongPredicate predicate) { - LongStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - long[] filteredStorage = new long[this.length]; - int filteredLength = 0; - int i = 0; - for (i = 0; i < this.length; i += 1) { - if (predicate.test(storage[i])) { - filteredStorage[filteredLength] = storage[i]; - filteredLength += 1; - } - } - ; - Engine.assume(filteredLength <= this.length); - long[] resultStorage = new long[filteredLength]; - LibSLRuntime.ArrayActions.copy(filteredStorage, 0, resultStorage, 0, filteredLength); - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ resultStorage, - /* length = */ filteredLength, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::map(LongStream, LongUnaryOperator) -> LongStream - * Source: java/util/stream/LongStream.main.lsl:213 - */ - public LongStream map(LongUnaryOperator mapper) { - LongStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (mapper == null) { - throw new NullPointerException(); - } - long[] mappedStorage = new long[this.length]; - int i = 0; - for (i = 0; i < this.length; i += 1) { - mappedStorage[i] = mapper.applyAsLong(storage[i]); - } - ; - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ mappedStorage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::mapToObj(LongStream, LongFunction) -> Stream - * Source: java/util/stream/LongStream.main.lsl:244 - */ - public Stream mapToObj(LongFunction mapper) { - Stream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - final Object[] objStorage = new Object[this.length]; - int i = 0; - for (i = 0; i < this.length; i += 1) { - objStorage[i] = mapper.apply(storage[i]); - } - ; - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ objStorage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::mapToInt(LongStream, LongToIntFunction) -> IntStream - * Source: java/util/stream/LongStream.main.lsl:273 - */ - public IntStream mapToInt(LongToIntFunction mapper) { - IntStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (mapper == null) { - throw new NullPointerException(); - } - int[] mappedStorage = new int[this.length]; - int i = 0; - for (i = 0; i < this.length; i += 1) { - mappedStorage[i] = mapper.applyAsInt(storage[i]); - } - ; - result = (stub.java.util.stream.IntStreamLSL) ((Object) new IntStreamLSL((Void) null, - /* state = */ IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ mappedStorage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::mapToDouble(LongStream, LongToDoubleFunction) -> DoubleStream - * Source: java/util/stream/LongStream.main.lsl:304 - */ - public DoubleStream mapToDouble(LongToDoubleFunction mapper) { - DoubleStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (mapper == null) { - throw new NullPointerException(); - } - double[] mappedStorage = new double[this.length]; - int i = 0; - for (i = 0; i < this.length; i += 1) { - mappedStorage[i] = mapper.applyAsDouble(storage[i]); - } - ; - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ mappedStorage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::flatMap(LongStream, LongFunction) -> LongStream - * Source: java/util/stream/LongStream.main.lsl:335 - */ - public LongStream flatMap(LongFunction mapper) { - LongStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (mapper == null) { - throw new NullPointerException(); - } - result = Engine.makeSymbolic(LongStream.class); - Engine.assume(result != null); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::sorted(LongStream) -> LongStream - * Source: java/util/stream/LongStream.main.lsl:351 - */ - public LongStream sorted() { - LongStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (this.length == 0) { - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ 0, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - Engine.assume(this.length > 0); - final int outerLimit = this.length - 1; - int innerLimit = 0; - int i = 0; - int j = 0; - for (i = 0; i < outerLimit; i += 1) { - innerLimit = (this.length - i) - 1; - for (j = 0; j < innerLimit; j += 1) { - final int idxA = j; - final int idxB = j + 1; - final long a = storage[idxA]; - final long b = storage[idxB]; - if (a > b) { - storage[idxA] = b; - storage[idxB] = a; - } - } - ; - } - ; - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::distinct(LongStream) -> LongStream - * Source: java/util/stream/LongStream.main.lsl:414 - */ - public LongStream distinct() { - LongStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - long[] distinctStorage = null; - int distinctLength = 0; - final int size = this.length; - if (size == 0) { - distinctStorage = new long[0]; - distinctLength = 0; - } else { - final long[] items = this.storage; - Engine.assume(items != null); - Engine.assume(items.length != 0); - Engine.assume(size == items.length); - int i = 0; - int j = 0; - final SymbolicList uniqueItems = Engine.makeSymbolicList(); - final LibSLRuntime.Map visited = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - for (i = 0; i < size; i += 1) { - final long item = items[i]; - if (!visited.hasKey(item)) { - visited.set(item, LibSLGlobals.SOMETHING); - uniqueItems.insert(j, item); - j += 1; - } - } - ; - distinctLength = j; - Engine.assume(distinctLength > 0); - Engine.assume(distinctLength <= size); - distinctStorage = new long[distinctLength]; - for (i = 0; i < distinctLength; i += 1) { - final Long item = uniqueItems.get(i); - Engine.assume(item != null); - distinctStorage[i] = ((long) item); - } - ; - } - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ distinctStorage, - /* length = */ distinctLength, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::peek(Stream, LongConsumer) -> LongStream - * Source: java/util/stream/LongStream.main.lsl:486 - */ - public LongStream peek(LongConsumer _action) { - LongStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - _actionApply(_action); - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::limit(LongStream, long) -> LongStream - * Source: java/util/stream/LongStream.main.lsl:502 - */ - public LongStream limit(long maxSize) { - LongStream result = null; - /* body */ { - final int maxSizeInt = ((int) maxSize); - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (maxSizeInt < 0) { - throw new IllegalArgumentException(); - } - if (maxSizeInt == 0) { - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ 0, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - if (maxSizeInt > this.length) { - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - final long[] limitStorage = new long[maxSizeInt]; - LibSLRuntime.ArrayActions.copy(this.storage, 0, limitStorage, 0, maxSizeInt); - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ limitStorage, - /* length = */ maxSizeInt, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::skip(LongStream, long) -> LongStream - * Source: java/util/stream/LongStream.main.lsl:544 - */ - public LongStream skip(long n) { - LongStream result = null; - /* body */ { - final int offset = ((int) n); - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (offset < 0) { - throw new IllegalArgumentException(); - } - if (offset == 0) { - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - if (offset >= this.length) { - long[] newArray = {}; - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ newArray, - /* length = */ 0, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - final int newLength = this.length - offset; - final long[] skipStorage = new long[newLength]; - int i = 0; - int skipIndex = 0; - for (i = offset; i < this.length; i += 1) { - skipStorage[skipIndex] = storage[i]; - skipIndex += 1; - } - ; - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ skipStorage, - /* length = */ newLength, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::forEach(LongStream, LongConsumer) -> void - * Source: java/util/stream/LongStream.main.lsl:600 - */ - public void forEach(LongConsumer _action) { - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - _actionApply(_action); - this.linkedOrConsumed = true; - } - } - - /** - * [FUNCTION] LongStreamAutomaton::forEachOrdered(LongStream, LongConsumer) -> void - * Source: java/util/stream/LongStream.main.lsl:609 - */ - public void forEachOrdered(LongConsumer _action) { - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - _actionApply(_action); - this.linkedOrConsumed = true; - } - } - - /** - * [FUNCTION] LongStreamAutomaton::toArray(LongStream) -> array - * Source: java/util/stream/LongStream.main.lsl:618 - */ - public long[] toArray() { - long[] result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = this.storage; - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::reduce(LongStream, long, LongBinaryOperator) -> long - * Source: java/util/stream/LongStream.main.lsl:627 - */ - public long reduce(long identity, LongBinaryOperator accumulator) { - long result = 0L; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (accumulator == null) { - throw new NullPointerException(); - } - result = identity; - if (this.length != 0) { - Engine.assume(this.length > 0); - int i = 0; - for (i = 0; i < this.length; i += 1) { - result = accumulator.applyAsLong(result, storage[i]); - } - ; - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::reduce(LongStream, LongBinaryOperator) -> OptionalLong - * Source: java/util/stream/LongStream.main.lsl:656 - */ - public OptionalLong reduce(LongBinaryOperator accumulator) { - OptionalLong result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (accumulator == null) { - throw new NullPointerException(); - } - if (this.length == 0) { - result = OptionalLong.empty(); - } else { - if (this.length > 0) { - long value = storage[0]; - int i = 0; - for (i = 1; i < this.length; i += 1) { - value = accumulator.applyAsLong(value, storage[i]); - } - ; - result = OptionalLong.of(value); - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::collect(LongStream, Supplier, ObjLongConsumer, BiConsumer) -> Object - * Source: java/util/stream/LongStream.main.lsl:690 - */ - public Object collect(Supplier supplier, ObjLongConsumer accumulator, BiConsumer combiner) { - Object result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (supplier == null) { - throw new NullPointerException(); - } - if (accumulator == null) { - throw new NullPointerException(); - } - if (combiner == null) { - throw new NullPointerException(); - } - result = supplier.get(); - int i = 0; - for (i = 0; i < this.length; i += 1) { - accumulator.accept(result, storage[i]); - } - ; - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::min(LongStream) -> OptionalLong - * Source: java/util/stream/LongStream.main.lsl:722 - */ - public OptionalLong min() { - OptionalLong result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (this.length == 0) { - result = OptionalLong.empty(); - } else { - long min = storage[0]; - int i = 0; - for (i = 1; i < this.length; i += 1) { - if (min > storage[i]) { - min = storage[i]; - } - } - ; - result = OptionalLong.of(min); - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::max(IntStream) -> OptionalLong - * Source: java/util/stream/LongStream.main.lsl:754 - */ - public OptionalLong max() { - OptionalLong result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (this.length == 0) { - result = OptionalLong.empty(); - } else { - long max = storage[0]; - int i = 0; - for (i = 1; i < this.length; i += 1) { - if (max < storage[i]) { - max = storage[i]; - } - } - ; - result = OptionalLong.of(max); - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::count(LongStream) -> long - * Source: java/util/stream/LongStream.main.lsl:786 - */ - public long count() { - long result = 0L; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = this.length; - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::anyMatch(LongStream, LongPredicate) -> boolean - * Source: java/util/stream/LongStream.main.lsl:795 - */ - public boolean anyMatch(LongPredicate predicate) { - boolean result = false; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - result = false; - int i = 0; - while ((i < this.length) && !predicate.test(storage[i])) { - i += 1; - } - ; - if (i < this.length) { - result = true; - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::allMatch(LongStream, LongPredicate) -> boolean - * Source: java/util/stream/LongStream.main.lsl:823 - */ - public boolean allMatch(LongPredicate predicate) { - boolean result = false; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - result = true; - if (this.length > 0) { - result = false; - int i = 0; - while ((i < this.length) && predicate.test(storage[i])) { - i += 1; - } - ; - if (i == this.length) { - result = true; - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::noneMatch(LongStream, LongPredicate) -> boolean - * Source: java/util/stream/LongStream.main.lsl:849 - */ - public boolean noneMatch(LongPredicate predicate) { - boolean result = false; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - result = true; - if (this.length > 0) { - result = false; - int i = 0; - while ((i < this.length) && !predicate.test(storage[i])) { - i += 1; - } - ; - if (i == this.length) { - result = true; - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::findFirst(LongStream) -> OptionalLong - * Source: java/util/stream/LongStream.main.lsl:875 - */ - public OptionalLong findFirst() { - OptionalLong result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = _findFirst(); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::findAny(LongStream) -> OptionalLong - * Source: java/util/stream/LongStream.main.lsl:884 - */ - public OptionalLong findAny() { - OptionalLong result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = _findFirst(); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::iterator(LongStream) -> PrimitiveIterator_OfLong - * Source: java/util/stream/LongStream.main.lsl:893 - */ - public PrimitiveIterator.OfLong iterator() { - PrimitiveIterator.OfLong result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = (stub.java.util.stream.LongStreamLSLIterator) ((Object) new LongStreamLSLIterator((Void) null, - /* state = */ LongStreamLSLIterator.__$lsl_States.Initialized, - /* parent = */ this, - /* cursor = */ 0 - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::spliterator(LongStream) -> Spliterator_OfLong - * Source: java/util/stream/LongStream.main.lsl:907 - */ - public Spliterator.OfLong spliterator() { - Spliterator.OfLong result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = (Spliterators_LongArraySpliterator) ((Object) new generated.java.util.Spliterators_LongArraySpliterator((Void) null, - /* state = */ generated.java.util.Spliterators_LongArraySpliterator.__$lsl_States.Initialized, - /* array = */ this.storage, - /* index = */ 0, - /* fence = */ this.length, - /* characteristics = */ LibSLGlobals.SPLITERATOR_ORDERED | LibSLGlobals.SPLITERATOR_IMMUTABLE | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::isParallel(LongStream) -> boolean - * Source: java/util/stream/LongStream.main.lsl:923 - */ - public boolean isParallel() { - boolean result = false; - /* body */ { - result = this.isParallel; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::sequential(LongStream) -> LongStream - * Source: java/util/stream/LongStream.main.lsl:929 - */ - public LongStream sequential() { - LongStream result = null; - /* body */ { - this.isParallel = false; - result = this; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::parallel(LongStream) -> LongStream - * Source: java/util/stream/LongStream.main.lsl:936 - */ - public LongStream parallel() { - LongStream result = null; - /* body */ { - this.isParallel = true; - result = this; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::unordered(LongStream) -> LongStream - * Source: java/util/stream/LongStream.main.lsl:943 - */ - public LongStream unordered() { - LongStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::onClose(LongStream, Runnable) -> LongStream - * Source: java/util/stream/LongStream.main.lsl:956 - */ - public LongStream onClose(Runnable closeHandler) { - LongStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - final int listLength = this.closeHandlers.size(); - this.closeHandlers.insert(listLength, closeHandler); - result = this; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::close(LongStream) -> void - * Source: java/util/stream/LongStream.main.lsl:968 - */ - public void close() { - /* body */ { - final int listLength = this.closeHandlers.size(); - int i = 0; - for (i = 0; i < listLength; i += 1) { - final Runnable currentHandler = ((Runnable) this.closeHandlers.get(i)); - currentHandler.run(); - } - ; - this.closeHandlers = Engine.makeSymbolicList(); - this.linkedOrConsumed = true; - } - } - - /** - * [FUNCTION] LongStreamAutomaton::dropWhile(LongStream, LongPredicate) -> LongStream - * Source: java/util/stream/LongStream.main.lsl:992 - */ - public LongStream dropWhile(LongPredicate predicate) { - LongStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - if (this.length == 0) { - final long[] emptyStorage = new long[0]; - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ emptyStorage, - /* length = */ 0, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - Engine.assume(this.length > 0); - int dropLength = 0; - int i = 0; - while ((i < this.length) && predicate.test(storage[i])) { - dropLength += 1; - i += 1; - } - ; - if (dropLength == 0) { - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - final int newLength = this.length - dropLength; - final long[] newStorage = new long[newLength]; - int j = dropLength; - i = dropLength; - while (i < this.length) { - newStorage[j] = storage[i]; - j += 1; - i += 1; - } - ; - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ newStorage, - /* length = */ newLength, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::takeWhile(LongStream, LongPredicate) -> LongStream - * Source: java/util/stream/LongStream.main.lsl:1067 - */ - public LongStream takeWhile(LongPredicate predicate) { - LongStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - if (this.length == 0) { - final long[] emptyStorage = new long[0]; - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ emptyStorage, - /* length = */ 0, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - Engine.assume(this.length > 0); - int takeLength = 0; - int i = 0; - while ((i < this.length) && predicate.test(storage[i])) { - takeLength += 1; - i += 1; - } - ; - if (takeLength == this.length) { - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - final int newLength = takeLength; - final long[] newStorage = new long[newLength]; - int j = 0; - i = 0; - while (i < takeLength) { - newStorage[j] = storage[i]; - j += 1; - i += 1; - } - ; - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ newStorage, - /* length = */ newLength, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::asDoubleStream(LongStream) -> DoubleStream - * Source: java/util/stream/LongStream.main.lsl:1142 - */ - public DoubleStream asDoubleStream() { - DoubleStream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (this.length == 0) { - final double[] emptyArray = {}; - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ emptyArray, - /* length = */ 0, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - Engine.assume(this.length > 0); - final double[] newStorage = new double[this.length]; - int i = 0; - for (i = 0; i < this.length; i += 1) { - newStorage[i] = ((double) storage[i]); - } - ; - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ newStorage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::sum(LongStream) -> long - * Source: java/util/stream/LongStream.main.lsl:1184 - */ - public long sum() { - long result = 0L; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = _sum(); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::average(LongStream) -> OptionalDouble - * Source: java/util/stream/LongStream.main.lsl:1194 - */ - public OptionalDouble average() { - OptionalDouble result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (this.length == 0) { - result = OptionalDouble.empty(); - } else { - double curSum = _sum(); - double divisionResult = curSum / this.length; - result = OptionalDouble.of(divisionResult); - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::summaryStatistics(LongStream) -> LongSummaryStatistics - * Source: java/util/stream/LongStream.main.lsl:1213 - */ - public LongSummaryStatistics summaryStatistics() { - LongSummaryStatistics result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = new LongSummaryStatistics(); - int i = 0; - for (i = 0; i < this.length; i += 1) { - result.accept(storage[i]); - } - ; - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] LongStreamAutomaton::boxed(LongStream) -> Stream - * Source: java/util/stream/LongStream.main.lsl:1234 - */ - public Stream boxed() { - Stream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - final Long[] longArray = new Long[this.length]; - int i = 0; - for (i = 0; i < this.length; i += 1) { - longArray[i] = storage[i]; - } - ; - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ longArray, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(LongStreamLSL.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/stream/LongStreamLSLIterator.java b/approximations/src/main/java/generated/java/util/stream/LongStreamLSLIterator.java deleted file mode 100644 index 7720db40..00000000 --- a/approximations/src/main/java/generated/java/util/stream/LongStreamLSLIterator.java +++ /dev/null @@ -1,169 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/stream/LongStream.lsl:35 -// - java/util/stream/LongStream.Iterator.lsl:18 -// -package generated.java.util.stream; - -import java.lang.Long; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.UnsupportedOperationException; -import java.lang.Void; -import java.util.NoSuchElementException; -import java.util.PrimitiveIterator; -import java.util.function.Consumer; -import java.util.function.LongConsumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * LongStreamIteratorAutomaton for LongStreamLSLIterator ~> java.util.stream.LongStreamLSLIterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.stream.LongStreamLSLIterator.class) -public class LongStreamLSLIterator implements LibSLRuntime.Automaton, PrimitiveIterator.OfLong { - static { - Engine.assume(true); - } - - public LongStreamLSL parent; - - public int cursor; - - @LibSLRuntime.AutomatonConstructor - public LongStreamLSLIterator(Void __$lsl_token, final byte p0, final LongStreamLSL p1, - final int p2) { - this.parent = p1; - this.cursor = p2; - } - - @LibSLRuntime.AutomatonConstructor - public LongStreamLSLIterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, 0); - } - - /** - * [FUNCTION] LongStreamIteratorAutomaton::hasNext(LongStreamLSLIterator) -> boolean - * Source: java/util/stream/LongStream.Iterator.lsl:41 - */ - public boolean hasNext() { - boolean result = false; - /* body */ { - Engine.assume(this.parent != null); - result = this.cursor != ((LongStreamLSL) ((Object) this.parent)).length; - } - return result; - } - - /** - * [FUNCTION] LongStreamIteratorAutomaton::next(LongStreamLSLIterator) -> Long - * Source: java/util/stream/LongStream.Iterator.lsl:50 - */ - public Long next() { - Long result = null; - /* body */ { - Engine.assume(this.parent != null); - final long[] parentStorage = ((LongStreamLSL) ((Object) this.parent)).storage; - final int i = this.cursor; - if (i >= ((LongStreamLSL) ((Object) this.parent)).length) { - throw new NoSuchElementException(); - } - this.cursor = i + 1; - result = parentStorage[i]; - } - return result; - } - - /** - * [FUNCTION] LongStreamIteratorAutomaton::nextLong(LongStreamLSLIterator) -> long - * Source: java/util/stream/LongStream.Iterator.lsl:66 - */ - public long nextLong() { - long result = 0L; - /* body */ { - Engine.assume(this.parent != null); - final long[] parentStorage = ((LongStreamLSL) ((Object) this.parent)).storage; - final int i = this.cursor; - if (i >= ((LongStreamLSL) ((Object) this.parent)).length) { - throw new NoSuchElementException(); - } - this.cursor = i + 1; - result = parentStorage[i]; - } - return result; - } - - /** - * [FUNCTION] LongStreamIteratorAutomaton::remove(LongStreamLSLIterator) -> void - * Source: java/util/stream/LongStream.Iterator.lsl:82 - */ - public void remove() { - /* body */ { - throw new UnsupportedOperationException(); - } - } - - /** - * [FUNCTION] LongStreamIteratorAutomaton::forEachRemaining(LongStreamLSLIterator, Consumer) -> void - * Source: java/util/stream/LongStream.Iterator.lsl:88 - */ - public void forEachRemaining(Consumer userAction) { - /* body */ { - Engine.assume(this.parent != null); - if (userAction == null) { - throw new NullPointerException(); - } - int i = this.cursor; - final int size = ((LongStreamLSL) ((Object) this.parent)).length; - if (i != size) { - final long[] pStorage = ((LongStreamLSL) ((Object) this.parent)).storage; - while (i < size) { - final long item = pStorage[i]; - userAction.accept(item); - i += 1; - } - ; - this.cursor = i; - } - } - } - - /** - * [FUNCTION] LongStreamIteratorAutomaton::forEachRemaining(LongStreamLSLIterator, LongConsumer) -> void - * Source: java/util/stream/LongStream.Iterator.lsl:113 - */ - public void forEachRemaining(LongConsumer userAction) { - /* body */ { - Engine.assume(this.parent != null); - if (userAction == null) { - throw new NullPointerException(); - } - int i = this.cursor; - final int size = ((LongStreamLSL) ((Object) this.parent)).length; - if (i != size) { - final long[] pStorage = ((LongStreamLSL) ((Object) this.parent)).storage; - while (i < size) { - final long item = pStorage[i]; - userAction.accept(item); - i += 1; - } - ; - this.cursor = i; - } - } - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(LongStreamLSLIterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/stream/StreamLSL.java b/approximations/src/main/java/generated/java/util/stream/StreamLSL.java deleted file mode 100644 index 1f888c3e..00000000 --- a/approximations/src/main/java/generated/java/util/stream/StreamLSL.java +++ /dev/null @@ -1,1369 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/stream/Stream.lsl:34 -// - java/util/stream/Stream.main.lsl:40 -// -package generated.java.util.stream; - -import generated.runtime.LibSLGlobals; -import java.lang.Comparable; -import java.lang.IllegalArgumentException; -import java.lang.IllegalStateException; -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.Runnable; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Comparator; -import java.util.Iterator; -import java.util.Optional; -import java.util.Spliterator; -import java.util.function.BiConsumer; -import java.util.function.BiFunction; -import java.util.function.BinaryOperator; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.IntFunction; -import java.util.function.Predicate; -import java.util.function.Supplier; -import java.util.function.ToDoubleFunction; -import java.util.function.ToIntFunction; -import java.util.function.ToLongFunction; -import java.util.stream.BaseStream; -import java.util.stream.Collector; -import java.util.stream.DoubleStream; -import java.util.stream.IntStream; -import java.util.stream.LongStream; -import java.util.stream.Stream; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import org.usvm.api.SymbolicList; -import runtime.LibSLRuntime; -import stub.java.util.Spliterators_ArraySpliterator; - -/** - * StreamAutomaton for StreamLSL ~> java.util.stream.StreamLSL - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.stream.StreamLSL.class) -public class StreamLSL implements LibSLRuntime.Automaton, Stream { - static { - Engine.assume(true); - } - - private byte __$lsl_state = __$lsl_States.Allocated; - - public Object[] storage; - - public transient int length; - - public SymbolicList closeHandlers; - - public boolean isParallel; - - public boolean linkedOrConsumed; - - @LibSLRuntime.AutomatonConstructor - public StreamLSL(Void __$lsl_token, final byte p0, final Object[] p1, final int p2, - final SymbolicList p3, final boolean p4, final boolean p5) { - this.__$lsl_state = p0; - this.storage = p1; - this.length = p2; - this.closeHandlers = p3; - this.isParallel = p4; - this.linkedOrConsumed = p5; - } - - @LibSLRuntime.AutomatonConstructor - public StreamLSL(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, null, 0, null, false, false); - } - - /** - * [SUBROUTINE] StreamAutomaton::_actionApply(Consumer) -> void - * Source: java/util/stream/Stream.main.lsl:134 - */ - private void _actionApply(Consumer _action) { - /* body */ { - if (_action == null) { - throw new NullPointerException(); - } - int i = 0; - for (i = 0; i < this.length; i += 1) { - _action.accept(storage[i]); - } - ; - } - } - - /** - * [SUBROUTINE] StreamAutomaton::_findFirst() -> Optional - * Source: java/util/stream/Stream.main.lsl:153 - */ - private Optional _findFirst() { - Optional result = null; - /* body */ { - if (this.length == 0) { - result = Optional.empty(); - } else { - final Object first = storage[0]; - result = Optional.ofNullable(first); - } - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::filter(Stream, Predicate) -> Stream - * Source: java/util/stream/Stream.main.lsl:169 - */ - public Stream filter(Predicate predicate) { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - Object[] filteredStorage = new Object[this.length]; - int filteredLength = 0; - int i = 0; - for (i = 0; i < this.length; i += 1) { - if (predicate.test(storage[i])) { - filteredStorage[filteredLength] = storage[i]; - filteredLength += 1; - } - } - ; - Engine.assume(filteredLength <= this.length); - Object[] resultStorage = new Object[filteredLength]; - LibSLRuntime.ArrayActions.copy(filteredStorage, 0, resultStorage, 0, filteredLength); - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ resultStorage, - /* length = */ filteredLength, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::map(Stream, Function) -> Stream - * Source: java/util/stream/Stream.main.lsl:210 - */ - public Stream map(Function mapper) { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (mapper == null) { - throw new NullPointerException(); - } - Object[] mappedStorage = new Object[this.length]; - int i = 0; - for (i = 0; i < this.length; i += 1) { - mappedStorage[i] = mapper.apply(storage[i]); - } - ; - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ mappedStorage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::mapToInt(Stream, ToIntFunction) -> IntStream - * Source: java/util/stream/Stream.main.lsl:241 - */ - public IntStream mapToInt(ToIntFunction mapper) { - IntStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (mapper == null) { - throw new NullPointerException(); - } - final int[] mappedStorage = new int[this.length]; - int i = 0; - for (i = 0; i < this.length; i += 1) { - mappedStorage[i] = mapper.applyAsInt(storage[i]); - } - ; - result = (stub.java.util.stream.IntStreamLSL) ((Object) new IntStreamLSL((Void) null, - /* state = */ IntStreamLSL.__$lsl_States.Initialized, - /* storage = */ mappedStorage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::mapToLong(Stream, ToLongFunction) -> LongStream - * Source: java/util/stream/Stream.main.lsl:272 - */ - public LongStream mapToLong(ToLongFunction mapper) { - LongStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (mapper == null) { - throw new NullPointerException(); - } - long[] mappedStorage = new long[this.length]; - int i = 0; - for (i = 0; i < this.length; i += 1) { - mappedStorage[i] = mapper.applyAsLong(storage[i]); - } - ; - result = (stub.java.util.stream.LongStreamLSL) ((Object) new LongStreamLSL((Void) null, - /* state = */ LongStreamLSL.__$lsl_States.Initialized, - /* storage = */ mappedStorage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::mapToDouble(Stream, ToDoubleFunction) -> DoubleStream - * Source: java/util/stream/Stream.main.lsl:303 - */ - public DoubleStream mapToDouble(ToDoubleFunction mapper) { - DoubleStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (mapper == null) { - throw new NullPointerException(); - } - double[] mappedStorage = new double[this.length]; - int i = 0; - for (i = 0; i < this.length; i += 1) { - mappedStorage[i] = mapper.applyAsDouble(storage[i]); - } - ; - result = (stub.java.util.stream.DoubleStreamLSL) ((Object) new DoubleStreamLSL((Void) null, - /* state = */ DoubleStreamLSL.__$lsl_States.Initialized, - /* storage = */ mappedStorage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::flatMap(Stream, Function) -> Stream - * Source: java/util/stream/Stream.main.lsl:334 - */ - public Stream flatMap(Function mapper) { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (mapper == null) { - throw new NullPointerException(); - } - result = Engine.makeSymbolic(Stream.class); - Engine.assume(result != null); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::flatMapToInt(Stream, Function) -> IntStream - * Source: java/util/stream/Stream.main.lsl:350 - */ - public IntStream flatMapToInt(Function mapper) { - IntStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (mapper == null) { - throw new NullPointerException(); - } - result = Engine.makeSymbolic(IntStream.class); - Engine.assume(result != null); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::flatMapToLong(Stream, Function) -> LongStream - * Source: java/util/stream/Stream.main.lsl:366 - */ - public LongStream flatMapToLong(Function mapper) { - LongStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (mapper == null) { - throw new NullPointerException(); - } - result = Engine.makeSymbolic(LongStream.class); - Engine.assume(result != null); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::flatMapToDouble(Stream, Function) -> DoubleStream - * Source: java/util/stream/Stream.main.lsl:382 - */ - public DoubleStream flatMapToDouble(Function mapper) { - DoubleStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (mapper == null) { - throw new NullPointerException(); - } - result = Engine.makeSymbolic(DoubleStream.class); - Engine.assume(result != null); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::distinct(Stream) -> Stream - * Source: java/util/stream/Stream.main.lsl:398 - */ - public Stream distinct() { - Stream result = null; - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - Object[] distinctStorage = null; - int distinctLength = 0; - final int size = this.length; - if (size == 0) { - distinctStorage = new Object[0]; - distinctLength = 0; - } else { - final Object[] items = this.storage; - Engine.assume(items != null); - Engine.assume(items.length != 0); - Engine.assume(size == items.length); - int i = 0; - int j = 0; - final SymbolicList uniqueItems = Engine.makeSymbolicList(); - final LibSLRuntime.Map visited = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); - for (i = 0; i < size; i += 1) { - final Object item = items[i]; - if (!visited.hasKey(item)) { - visited.set(item, LibSLGlobals.SOMETHING); - uniqueItems.insert(j, item); - j += 1; - } - } - ; - distinctLength = j; - Engine.assume(distinctLength > 0); - Engine.assume(distinctLength <= size); - distinctStorage = new Object[distinctLength]; - for (i = 0; i < distinctLength; i += 1) { - distinctStorage[i] = uniqueItems.get(i); - } - ; - } - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ distinctStorage, - /* length = */ distinctLength, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::sorted(Stream) -> Stream - * Source: java/util/stream/Stream.main.lsl:468 - */ - public Stream sorted() { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (this.length == 0) { - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - Engine.assume(this.length > 0); - final int outerLimit = this.length - 1; - int innerLimit = 0; - int i = 0; - int j = 0; - for (i = 0; i < outerLimit; i += 1) { - innerLimit = (this.length - i) - 1; - for (j = 0; j < innerLimit; j += 1) { - final int idxA = j; - final int idxB = j + 1; - final Object a = storage[idxA]; - final Object b = storage[idxB]; - if (((Comparable) a).compareTo(b) > 0) { - storage[idxA] = b; - storage[idxB] = a; - } - } - ; - } - ; - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::sorted(Stream, Comparator) -> Stream - * Source: java/util/stream/Stream.main.lsl:531 - */ - public Stream sorted(Comparator comparator) { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (this.length == 0) { - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - final int outerLimit = this.length - 1; - int innerLimit = 0; - int i = 0; - int j = 0; - for (i = 0; i < outerLimit; i += 1) { - innerLimit = (this.length - i) - 1; - for (j = 0; j < innerLimit; j += 1) { - final int idxA = j; - final int idxB = j + 1; - final Object a = storage[idxA]; - final Object b = storage[idxB]; - if (comparator.compare(a, b) > 0) { - storage[idxA] = b; - storage[idxB] = a; - } - } - ; - } - ; - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::peek(Stream, Consumer) -> Stream - * Source: java/util/stream/Stream.main.lsl:591 - */ - public Stream peek(Consumer _action) { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - _actionApply(_action); - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::limit(Stream, long) -> Stream - * Source: java/util/stream/Stream.main.lsl:608 - */ - public Stream limit(long maxSize) { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (maxSize < 0) { - throw new IllegalArgumentException(); - } - if (maxSize == 0) { - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ 0, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - if (maxSize > this.length) { - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - final int maxSizeInt = ((int) maxSize); - final Object[] limitStorage = new Object[maxSizeInt]; - int i = 0; - for (i = 0; i < maxSizeInt; i += 1) { - limitStorage[i] = storage[i]; - } - ; - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ limitStorage, - /* length = */ maxSizeInt, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::skip(Stream, long) -> Stream - * Source: java/util/stream/Stream.main.lsl:661 - */ - public Stream skip(long n) { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int offset = ((int) n); - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (offset < 0) { - throw new IllegalArgumentException(); - } - if (offset == 0) { - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - if (offset >= this.length) { - Object[] newArray = {}; - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ newArray, - /* length = */ 0, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - final int newLength = this.length - offset; - final Object[] skipStorage = new Object[newLength]; - int i = 0; - int skipIndex = 0; - for (i = offset; i < this.length; i += 1) { - skipStorage[skipIndex] = storage[i]; - skipIndex += 1; - } - ; - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ skipStorage, - /* length = */ newLength, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::forEach(Stream, Consumer) -> void - * Source: java/util/stream/Stream.main.lsl:717 - */ - public void forEach(Consumer _action) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - _actionApply(_action); - this.linkedOrConsumed = true; - } - } - - /** - * [FUNCTION] StreamAutomaton::forEachOrdered(Stream, Consumer) -> void - * Source: java/util/stream/Stream.main.lsl:726 - */ - public void forEachOrdered(Consumer _action) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - _actionApply(_action); - this.linkedOrConsumed = true; - } - } - - /** - * [FUNCTION] StreamAutomaton::toArray(Stream) -> array - * Source: java/util/stream/Stream.main.lsl:735 - */ - public Object[] toArray() { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = this.storage; - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::toArray(Stream, IntFunction) -> array - * Source: java/util/stream/Stream.main.lsl:744 - */ - public Object[] toArray(IntFunction generator) { - Object[] result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - final Object[] generatedArray = ((Object[]) generator.apply(this.length)); - LibSLRuntime.ArrayActions.copy(this.storage, 0, generatedArray, 0, this.length); - result = generatedArray; - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::reduce(Stream, Object, BinaryOperator) -> Object - * Source: java/util/stream/Stream.main.lsl:757 - */ - public Object reduce(Object identity, BinaryOperator accumulator) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (accumulator == null) { - throw new NullPointerException(); - } - result = identity; - if (this.length != 0) { - Engine.assume(this.length > 0); - int i = 0; - for (i = 0; i < this.length; i += 1) { - result = accumulator.apply(result, storage[i]); - } - ; - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::reduce(Stream, BinaryOperator) -> Optional - * Source: java/util/stream/Stream.main.lsl:786 - */ - public Optional reduce(BinaryOperator accumulator) { - Optional result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (accumulator == null) { - throw new NullPointerException(); - } - Object value = null; - if (this.length == 0) { - result = Optional.empty(); - } else { - if (this.length > 0) { - value = storage[0]; - int i = 0; - for (i = 1; i < this.length; i += 1) { - value = accumulator.apply(value, storage[i]); - } - ; - result = Optional.ofNullable(value); - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::reduce(Stream, Object, BiFunction, BinaryOperator) -> Object - * Source: java/util/stream/Stream.main.lsl:822 - */ - public Object reduce(Object identity, BiFunction accumulator, BinaryOperator combiner) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (accumulator == null) { - throw new NullPointerException(); - } - if (combiner == null) { - throw new NullPointerException(); - } - result = identity; - if (this.length != 0) { - Engine.assume(this.length > 0); - int i = 0; - for (i = 0; i < this.length; i += 1) { - result = accumulator.apply(result, storage[i]); - } - ; - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::collect(Stream, Supplier, BiConsumer, BiConsumer) -> Object - * Source: java/util/stream/Stream.main.lsl:855 - */ - public Object collect(Supplier supplier, BiConsumer accumulator, BiConsumer combiner) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (supplier == null) { - throw new NullPointerException(); - } - if (accumulator == null) { - throw new NullPointerException(); - } - if (combiner == null) { - throw new NullPointerException(); - } - result = supplier.get(); - int i = 0; - for (i = 0; i < this.length; i += 1) { - accumulator.accept(result, storage[i]); - } - ; - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::collect(Stream, Collector) -> Object - * Source: java/util/stream/Stream.main.lsl:887 - */ - public Object collect(Collector collector) { - Object result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (collector == null) { - throw new NullPointerException(); - } - int i = 0; - final BiConsumer accumulator = collector.accumulator(); - for (i = 0; i < this.length; i += 1) { - accumulator.accept(result, storage[i]); - } - ; - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::min(Stream, Comparator) -> Optional - * Source: java/util/stream/Stream.main.lsl:905 - */ - public Optional min(Comparator comparator) { - Optional result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (comparator == null) { - throw new NullPointerException(); - } - if (this.length == 0) { - result = Optional.empty(); - } else { - Object min = storage[0]; - int i = 0; - for (i = 1; i < this.length; i += 1) { - if (comparator.compare(min, storage[i]) > 0) { - min = storage[i]; - } - } - ; - result = Optional.ofNullable(min); - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::max(Stream, Comparator) -> Optional - * Source: java/util/stream/Stream.main.lsl:940 - */ - public Optional max(Comparator comparator) { - Optional result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (comparator == null) { - throw new NullPointerException(); - } - if (this.length == 0) { - result = Optional.empty(); - } else { - Object max = storage[0]; - int i = 0; - for (i = 1; i < this.length; i += 1) { - if (comparator.compare(max, storage[i]) < 0) { - max = storage[i]; - } - } - ; - result = Optional.ofNullable(max); - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::count(Stream) -> long - * Source: java/util/stream/Stream.main.lsl:975 - */ - public long count() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = this.length; - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::anyMatch(Stream, Predicate) -> boolean - * Source: java/util/stream/Stream.main.lsl:984 - */ - public boolean anyMatch(Predicate predicate) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - result = false; - int i = 0; - while ((i < this.length) && !predicate.test(storage[i])) { - i += 1; - } - ; - if (i < this.length) { - result = true; - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::allMatch(Stream, Predicate) -> boolean - * Source: java/util/stream/Stream.main.lsl:1012 - */ - public boolean allMatch(Predicate predicate) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - result = true; - if (this.length > 0) { - result = false; - int i = 0; - while ((i < this.length) && predicate.test(storage[i])) { - i += 1; - } - ; - if (i == this.length) { - result = true; - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::noneMatch(Stream, Predicate) -> boolean - * Source: java/util/stream/Stream.main.lsl:1038 - */ - public boolean noneMatch(Predicate predicate) { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - result = true; - if (this.length > 0) { - result = false; - int i = 0; - while ((i < this.length) && !predicate.test(storage[i])) { - i += 1; - } - ; - if (i == this.length) { - result = true; - } - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::findFirst(Stream) -> Optional - * Source: java/util/stream/Stream.main.lsl:1064 - */ - public Optional findFirst() { - Optional result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = _findFirst(); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::findAny(Stream) -> Optional - * Source: java/util/stream/Stream.main.lsl:1073 - */ - public Optional findAny() { - Optional result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = _findFirst(); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::iterator(Stream) -> Iterator - * Source: java/util/stream/Stream.main.lsl:1083 - */ - public Iterator iterator() { - Iterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = (stub.java.util.stream.StreamLSLIterator) ((Object) new StreamLSLIterator((Void) null, - /* state = */ StreamLSLIterator.__$lsl_States.Initialized, - /* parent = */ this, - /* cursor = */ 0 - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::spliterator(Stream) -> Spliterator - * Source: java/util/stream/Stream.main.lsl:1097 - */ - public Spliterator spliterator() { - Spliterator result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = (Spliterators_ArraySpliterator) ((Object) new generated.java.util.Spliterators_ArraySpliterator((Void) null, - /* state = */ generated.java.util.Spliterators_ArraySpliterator.__$lsl_States.Initialized, - /* array = */ this.storage, - /* index = */ 0, - /* fence = */ this.length, - /* characteristics = */ LibSLGlobals.SPLITERATOR_ORDERED | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::isParallel(Stream) -> boolean - * Source: java/util/stream/Stream.main.lsl:1113 - */ - public boolean isParallel() { - boolean result = false; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = this.isParallel; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::sequential(Stream) -> BaseStream - * Source: java/util/stream/Stream.main.lsl:1120 - */ - public BaseStream sequential() { - BaseStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.isParallel = false; - result = this; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::parallel(Stream) -> BaseStream - * Source: java/util/stream/Stream.main.lsl:1128 - */ - public BaseStream parallel() { - BaseStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.isParallel = true; - result = this; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::unordered(Stream) -> BaseStream - * Source: java/util/stream/Stream.main.lsl:1136 - */ - public BaseStream unordered() { - BaseStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ this.storage, - /* length = */ this.length, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::onClose(Stream, Runnable) -> BaseStream - * Source: java/util/stream/Stream.main.lsl:1149 - */ - public BaseStream onClose(Runnable arg0) { - BaseStream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - final int listLength = this.closeHandlers.size(); - this.closeHandlers.insert(listLength, arg0); - result = this; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::close(Stream) -> void - * Source: java/util/stream/Stream.main.lsl:1161 - */ - public void close() { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int listLength = this.closeHandlers.size(); - int i = 0; - for (i = 0; i < listLength; i += 1) { - final Runnable currentHandler = ((Runnable) this.closeHandlers.get(i)); - currentHandler.run(); - } - ; - this.closeHandlers = Engine.makeSymbolicList(); - this.linkedOrConsumed = true; - } - } - - /** - * [FUNCTION] StreamAutomaton::dropWhile(Stream, Predicate) -> Stream - * Source: java/util/stream/Stream.main.lsl:1185 - */ - public Stream dropWhile(Predicate predicate) { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - if (this.length == 0) { - final Object[] emptyStorage = new Object[0]; - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ emptyStorage, - /* length = */ 0, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - int dropLength = 0; - int i = 0; - for (i = 0; i < this.length; i += 1) { - if (predicate.test(storage[i])) { - dropLength += 1; - } else { - break; - } - } - ; - final int newLength = this.length - dropLength; - final Object[] newStorage = new Object[newLength]; - int j = 0; - for (i = dropLength; i < this.length; i += 1) { - newStorage[j] = storage[i]; - j += 1; - } - ; - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ newStorage, - /* length = */ newLength, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - this.linkedOrConsumed = true; - } - return result; - } - - /** - * [FUNCTION] StreamAutomaton::takeWhile(Stream, Predicate) -> Stream - * Source: java/util/stream/Stream.main.lsl:1247 - */ - public Stream takeWhile(Predicate predicate) { - Stream result = null; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - if (this.linkedOrConsumed) { - throw new IllegalStateException(); - } - if (predicate == null) { - throw new NullPointerException(); - } - if (this.length == 0) { - final Object[] emptyStorage = new Object[0]; - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ emptyStorage, - /* length = */ 0, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } else { - int takeLength = 0; - int i = 0; - for (i = 0; i < this.length; i += 1) { - if (predicate.test(storage[i])) { - takeLength += 1; - } else { - break; - } - } - ; - final int newLength = takeLength; - final Object[] newStorage = new Object[newLength]; - int j = 0; - for (i = 0; i < takeLength; i += 1) { - newStorage[j] = storage[i]; - j += 1; - } - ; - result = (stub.java.util.stream.StreamLSL) ((Object) new StreamLSL((Void) null, - /* state = */ StreamLSL.__$lsl_States.Initialized, - /* storage = */ newStorage, - /* length = */ newLength, - /* closeHandlers = */ this.closeHandlers, - /* isParallel = */ false, - /* linkedOrConsumed = */ false - )); - } - this.linkedOrConsumed = true; - } - return result; - } - - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; - } - - @Approximate(StreamLSL.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/stream/StreamLSLIterator.java b/approximations/src/main/java/generated/java/util/stream/StreamLSLIterator.java deleted file mode 100644 index c42944e1..00000000 --- a/approximations/src/main/java/generated/java/util/stream/StreamLSLIterator.java +++ /dev/null @@ -1,122 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/stream/Stream.lsl:43 -// - java/util/stream/Stream.Iterator.lsl:16 -// -package generated.java.util.stream; - -import java.lang.NullPointerException; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.UnsupportedOperationException; -import java.lang.Void; -import java.util.Iterator; -import java.util.NoSuchElementException; -import java.util.function.Consumer; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * StreamIteratorAutomaton for StreamLSLIterator ~> java.util.stream.StreamLSLIterator - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.java.util.stream.StreamLSLIterator.class) -public class StreamLSLIterator implements LibSLRuntime.Automaton, Iterator { - static { - Engine.assume(true); - } - - public StreamLSL parent; - - public int cursor; - - @LibSLRuntime.AutomatonConstructor - public StreamLSLIterator(Void __$lsl_token, final byte p0, final StreamLSL p1, final int p2) { - this.parent = p1; - this.cursor = p2; - } - - @LibSLRuntime.AutomatonConstructor - public StreamLSLIterator(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, null, 0); - } - - /** - * [FUNCTION] StreamIteratorAutomaton::hasNext(StreamLSLIterator) -> boolean - * Source: java/util/stream/Stream.Iterator.lsl:37 - */ - public boolean hasNext() { - boolean result = false; - /* body */ { - Engine.assume(this.parent != null); - result = this.cursor != ((StreamLSL) ((Object) this.parent)).length; - } - return result; - } - - /** - * [FUNCTION] StreamIteratorAutomaton::next(StreamLSLIterator) -> Object - * Source: java/util/stream/Stream.Iterator.lsl:46 - */ - public Object next() { - Object result = null; - /* body */ { - Engine.assume(this.parent != null); - final Object[] parentStorage = ((StreamLSL) ((Object) this.parent)).storage; - final int i = this.cursor; - if (i >= ((StreamLSL) ((Object) this.parent)).length) { - throw new NoSuchElementException(); - } - this.cursor = i + 1; - result = parentStorage[i]; - } - return result; - } - - /** - * [FUNCTION] StreamIteratorAutomaton::remove(StreamLSLIterator) -> void - * Source: java/util/stream/Stream.Iterator.lsl:62 - */ - public void remove() { - /* body */ { - throw new UnsupportedOperationException(); - } - } - - /** - * [FUNCTION] StreamIteratorAutomaton::forEachRemaining(StreamLSLIterator, Consumer) -> void - * Source: java/util/stream/Stream.Iterator.lsl:68 - */ - public void forEachRemaining(Consumer userAction) { - /* body */ { - Engine.assume(this.parent != null); - if (userAction == null) { - throw new NullPointerException(); - } - int i = this.cursor; - final int size = ((StreamLSL) ((Object) this.parent)).length; - if (i != size) { - final Object[] pStorage = ((StreamLSL) ((Object) this.parent)).storage; - while (i < size) { - final Object item = pStorage[i]; - userAction.accept(item); - i += 1; - } - ; - this.cursor = i; - } - } - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(StreamLSLIterator.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/java/util/stream/StreamStubImpl.java b/approximations/src/main/java/generated/java/util/stream/StreamStubImpl.java new file mode 100644 index 00000000..c404dd87 --- /dev/null +++ b/approximations/src/main/java/generated/java/util/stream/StreamStubImpl.java @@ -0,0 +1,699 @@ +package generated.java.util.stream; + +import generated.java.util.array.ArrayIteratorImpl; +import generated.java.util.array.ArraySpliteratorImpl; +import generated.runtime.LibSLGlobals; + +import java.lang.Comparable; +import java.lang.IllegalArgumentException; +import java.lang.NullPointerException; +import java.lang.Object; +import java.lang.Runnable; +import java.util.*; +import java.util.function.BiConsumer; +import java.util.function.BiFunction; +import java.util.function.BinaryOperator; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.IntFunction; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.function.ToDoubleFunction; +import java.util.function.ToIntFunction; +import java.util.function.ToLongFunction; +import java.util.stream.Collector; +import java.util.stream.DoubleStream; +import java.util.stream.IntStream; +import java.util.stream.LongStream; +import java.util.stream.Stream; + +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; +import org.usvm.api.SymbolicList; +import runtime.LibSLRuntime; +import stub.java.util.stream.StreamStub; + +@Approximate(StreamStub.class) +public class StreamStubImpl extends BaseStreamImpl implements Stream { + + private final E[] storage; + + public StreamStubImpl( + E[] storage, + SymbolicList handlers, + boolean isParallel, + boolean linkedOrConsumed + ) { + super(handlers, isParallel, linkedOrConsumed); + this.storage = storage; + } + + public StreamStubImpl(E[] storage, SymbolicList handlers, boolean isParallel) { + this(storage, handlers, isParallel, false); + } + + public StreamStubImpl(E[] storage, boolean isParallel) { + this(storage, Engine.makeSymbolicList(), isParallel); + } + + public StreamStubImpl(E[] storage, SymbolicList handlers) { + this(storage, handlers, false); + } + + public StreamStubImpl(E[] storage) { + this(storage, Engine.makeSymbolicList()); + } + + @SuppressWarnings({"ConstantValue", "DataFlowIssue"}) + private E[] _getStorage() { + E[] storage = this.storage; + Engine.assume(storage != null); + Engine.assume(storage.length >= 0); + return storage; + } + + protected int _getLength() { + return _getStorage().length; + } + + private StreamStubImpl _copy(T[] storage) { + return new StreamStubImpl<>(storage, _getCloseHandlers(), isParallel, linkedOrConsumed); + } + + private StreamStubImpl _copy() { + return _copy(_getStorage()); + } + + private void _actionApply(Consumer _action) { + if (_action == null) + throw new NullPointerException(); + + E[] storage = _getStorage(); + for (E e : storage) { + _action.accept(e); + } + } + + private Optional _findFirst() { + E[] storage = _getStorage(); + + if (storage.length == 0) + return Optional.empty(); + + E first = storage[0]; + return Optional.ofNullable(first); + } + + public Stream filter(Predicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + E[] storage = _getStorage(); + int length = storage.length; + E[] filteredStorage = Arrays.copyOf(storage, length); + int filteredLength = 0; + for (E e : storage) { + if (predicate.test(e)) { + filteredStorage[filteredLength] = e; + filteredLength++; + } + } + + Engine.assume(filteredLength <= length); + E[] resultStorage = Arrays.copyOf(filteredStorage, filteredLength); + return _copy(resultStorage); + } + + @SuppressWarnings("unchecked") + public Stream map(Function mapper) { + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + E[] storage = _getStorage(); + int length = storage.length; + T[] mappedStorage = (T[]) new Object[length]; + for (int i = 0; i < length; i++) { + mappedStorage[i] = mapper.apply(storage[i]); + } + + return _copy(mappedStorage); + } + + public IntStream mapToInt(ToIntFunction mapper) { + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + E[] storage = _getStorage(); + int length = storage.length; + int[] mappedStorage = new int[length]; + for (int i = 0; i < length; i++) { + mappedStorage[i] = mapper.applyAsInt(storage[i]); + } + + return _copyToIntStream(mappedStorage); + } + + public LongStream mapToLong(ToLongFunction mapper) { + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + E[] storage = _getStorage(); + int length = storage.length; + long[] mappedStorage = new long[length]; + for (int i = 0; i < length; i++) { + mappedStorage[i] = mapper.applyAsLong(storage[i]); + } + + return _copyToLongStream(mappedStorage); + } + + public DoubleStream mapToDouble(ToDoubleFunction mapper) { + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + E[] storage = _getStorage(); + int length = storage.length; + double[] mappedStorage = new double[length]; + for (int i = 0; i < length; i++) { + mappedStorage[i] = mapper.applyAsDouble(storage[i]); + } + + return _copyToDoubleStream(mappedStorage); + } + + @SuppressWarnings({"unchecked", "ConstantValue"}) + public Stream flatMap(Function> mapper) { + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + // TODO: approximate + Stream result = Engine.makeSymbolic(Stream.class); + Engine.assume(result != null); + return result; + } + + @SuppressWarnings("ConstantValue") + public IntStream flatMapToInt(Function mapper) { + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + // TODO: approximate + IntStream result = Engine.makeSymbolic(IntStream.class); + Engine.assume(result != null); + return result; + } + + @SuppressWarnings("ConstantValue") + public LongStream flatMapToLong(Function mapper) { + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + // TODO: approximate + LongStream result = Engine.makeSymbolic(LongStream.class); + Engine.assume(result != null); + return result; + } + + @SuppressWarnings("ConstantValue") + public DoubleStream flatMapToDouble(Function mapper) { + super.evaluate(); + + if (mapper == null) + throw new NullPointerException(); + + // TODO: approximate + DoubleStream result = Engine.makeSymbolic(DoubleStream.class); + Engine.assume(result != null); + return result; + } + + public StreamStubImpl distinct() { + super.evaluate(); + + E[] storage = _getStorage(); + E[] distinctStorage; + int length = storage.length; + if (length == 0) { + distinctStorage = Arrays.copyOf(storage, 0); + return _copy(distinctStorage); + } + + int distinctLength = 0; + distinctStorage = Arrays.copyOf(storage, length); + LibSLRuntime.Map visited = new LibSLRuntime.Map<>(new LibSLRuntime.HashMapContainer<>()); + for (E item : storage) { + if (!visited.hasKey(item)) { + Engine.assume(item != null); + visited.set(item, LibSLGlobals.SOMETHING); + distinctStorage[distinctLength] = item; + distinctLength++; + } + } + + Engine.assume(distinctLength <= length); + E[] resultStorage = Arrays.copyOf(distinctStorage, distinctLength); + return _copy(resultStorage); + } + + @SuppressWarnings("unchecked") + public StreamStubImpl sorted() { + super.evaluate(); + + E[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return _copy(); + + int outerLimit = length - 1; + for (int i = 0; i < outerLimit; i++) { + int innerLimit = length - i - 1; + for (int j = 0; j < innerLimit; j++) { + int idxB = j + 1; + Comparable a = (Comparable) storage[j]; + E b = storage[idxB]; + if (a.compareTo(b) > 0) { + storage[j] = b; + storage[idxB] = (E) a; + } + } + } + + return _copy(); + } + + public StreamStubImpl sorted(Comparator comparator) { + super.evaluate(); + + E[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return _copy(); + + int outerLimit = length - 1; + for (int i = 0; i < outerLimit; i++) { + int innerLimit = length - i - 1; + for (int j = 0; j < innerLimit; j++) { + int idxB = j + 1; + E a = storage[j]; + E b = storage[idxB]; + if (comparator.compare(a, b) > 0) { + storage[j] = b; + storage[idxB] = a; + } + } + } + + return _copy(); + } + + public StreamStubImpl peek(Consumer _action) { + super.evaluate(); + _actionApply(_action); + return _copy(); + } + + public StreamStubImpl limit(long maxSize) { + super.evaluate(); + + int maxSizeInt = (int) maxSize; + + if (maxSizeInt < 0) + throw new IllegalArgumentException(); + + if (maxSizeInt == 0) + return _copy(Arrays.copyOf(_getStorage(), 0)); + + E[] storage = _getStorage(); + int length = storage.length; + if (maxSizeInt > length) + return _copy(); + + E[] limitStorage = Arrays.copyOf(storage, maxSizeInt); + return _copy(limitStorage); + } + + public StreamStubImpl skip(long n) { + super.evaluate(); + + int offset = (int) n; + + if (offset < 0) + throw new IllegalArgumentException(); + + if (offset == 0) + return _copy(); + + E[] storage = _getStorage(); + int length = storage.length; + if (offset >= length) + return _copy(Arrays.copyOf(_getStorage(), 0)); + + E[] skipStorage = Arrays.copyOfRange(storage, offset, length); + return _copy(skipStorage); + } + + public void forEach(Consumer _action) { + super.evaluate(); + _actionApply(_action); + } + + public void forEachOrdered(Consumer _action) { + forEach(_action); + } + + @NotNull + public Object[] toArray() { + super.evaluate(); + return _getStorage(); + } + + @NotNull + @SuppressWarnings("unchecked") + public T[] toArray(IntFunction generator) { + super.evaluate(); + E[] storage = _getStorage(); + int length = storage.length; + + T[] array = generator.apply(length); + if (array.length < length) + return (T[]) Arrays.copyOf(storage, length, array.getClass()); + + LibSLRuntime.ArrayActions.copy(storage, 0, array, 0, length); + return array; + } + + public E reduce(E identity, BinaryOperator accumulator) { + super.evaluate(); + + if (accumulator == null) + throw new NullPointerException(); + + E result = identity; + E[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return result; + + for (E item : storage) { + result = accumulator.apply(result, item); + } + + return result; + } + + @NotNull + public Optional reduce(BinaryOperator accumulator) { + super.evaluate(); + + if (accumulator == null) + throw new NullPointerException(); + + E[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return Optional.empty(); + + E value = storage[0]; + for (int i = 1; i < length; i++) { + value = accumulator.apply(value, storage[i]); + } + + return Optional.of(value); + } + + public T reduce(T identity, BiFunction accumulator, BinaryOperator combiner) { + super.evaluate(); + + if (accumulator == null) + throw new NullPointerException(); + + if (combiner == null) + throw new NullPointerException(); + + T result = identity; + E[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return result; + + for (E item : storage) { + result = accumulator.apply(result, item); + } + + return result; + } + + private R _collect(Supplier supplier, BiConsumer accumulator) { + R result = supplier.get(); + E[] storage = _getStorage(); + for (E item : storage) { + accumulator.accept(result, item); + } + + return result; + } + + public R collect(Supplier supplier, BiConsumer accumulator, BiConsumer combiner) { + super.evaluate(); + + if (supplier == null) + throw new NullPointerException(); + + if (accumulator == null) + throw new NullPointerException(); + + if (combiner == null) + throw new NullPointerException(); + + return _collect(supplier, accumulator); + } + + public R collect(Collector collector) { + super.evaluate(); + + if (collector == null) + throw new NullPointerException(); + + return collector.finisher().apply(_collect(collector.supplier(), collector.accumulator())); + } + + @NotNull + public Optional min(Comparator comparator) { + super.evaluate(); + + if (comparator == null) + throw new NullPointerException(); + + E[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return Optional.empty(); + + E min = storage[0]; + for (int i = 1; i < length; i++) { + E item = storage[i]; + if (comparator.compare(min, item) > 0) + min = item; + } + + return Optional.ofNullable(min); + } + + @NotNull + public Optional max(Comparator comparator) { + super.evaluate(); + + if (comparator == null) + throw new NullPointerException(); + + E[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return Optional.empty(); + + E max = storage[0]; + for (int i = 1; i < length; i++) { + E item = storage[i]; + if (comparator.compare(max, item) < 0) + max = item; + } + + return Optional.ofNullable(max); + } + + public long count() { + super.evaluate(); + return _getStorage().length; + } + + public boolean anyMatch(Predicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + E[] storage = _getStorage(); + for (E item : storage) { + if (predicate.test(item)) + return true; + } + + return false; + } + + public boolean allMatch(Predicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + E[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return true; + + for (E item : storage) { + if (!predicate.test(item)) + return false; + } + + return true; + } + + public boolean noneMatch(Predicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + E[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return true; + + for (E item : storage) { + if (predicate.test(item)) + return false; + } + + return true; + } + + @NotNull + public Optional findFirst() { + super.evaluate(); + return _findFirst(); + } + + @NotNull + public Optional findAny() { + return findFirst(); + } + + @NotNull + public Iterator iterator() { + super.evaluate(); + return new ArrayIteratorImpl<>(_getStorage()); + } + + @NotNull + public Spliterator spliterator() { + super.evaluate(); + E[] storage = _getStorage(); + int characteristics = LibSLGlobals.SPLITERATOR_ORDERED | LibSLGlobals.SPLITERATOR_SIZED | LibSLGlobals.SPLITERATOR_SUBSIZED; + return new ArraySpliteratorImpl<>(storage, characteristics); + } + + public boolean isParallel() { + return this.isParallel; + } + + @NotNull + public StreamStubImpl sequential() { + return (StreamStubImpl) super.sequential(); + } + + @NotNull + public StreamStubImpl parallel() { + return (StreamStubImpl) super.parallel(); + } + + @NotNull + public StreamStubImpl unordered() { + super.evaluate(); + return _copy(); + } + + @NotNull + public StreamStubImpl onClose(@NotNull Runnable handler) { + return (StreamStubImpl) super.onClose(handler); + } + + public void close() { + super.close(); + } + + public StreamStubImpl dropWhile(Predicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + E[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return _copy(Arrays.copyOf(storage, 0)); + + int dropLength = 0; + while (dropLength < length && predicate.test(storage[dropLength])) { + dropLength++; + } + + if (dropLength == 0) + return _copy(); + + int newLength = length - dropLength; + E[] newStorage = Arrays.copyOf(storage, newLength); + return _copy(newStorage); + } + + public StreamStubImpl takeWhile(Predicate predicate) { + super.evaluate(); + + if (predicate == null) + throw new NullPointerException(); + + E[] storage = _getStorage(); + int length = storage.length; + if (length == 0) + return _copy(Arrays.copyOf(storage, 0)); + + int takeLength = 0; + while (takeLength < length && predicate.test(storage[takeLength])) { + takeLength++; + } + + if (takeLength == length) + return _copy(); + + E[] newStorage = Arrays.copyOf(storage, takeLength); + return _copy(newStorage); + } +} diff --git a/approximations/src/main/java/generated/java/util/zip/CRC32.java b/approximations/src/main/java/generated/java/util/zip/CRC32.java index dfd4c667..39dc5ff9 100644 --- a/approximations/src/main/java/generated/java/util/zip/CRC32.java +++ b/approximations/src/main/java/generated/java/util/zip/CRC32.java @@ -1,238 +1,136 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/zip/CRC32.lsl:23 -// - java/util/zip/CRC32.automaton.lsl:18 -// package generated.java.util.zip; import java.lang.ArrayIndexOutOfBoundsException; import java.lang.AssertionError; import java.lang.NullPointerException; import java.lang.SuppressWarnings; -import java.lang.Void; import java.nio.ByteBuffer; import java.util.zip.Checksum; import org.jacodb.approximation.annotation.Approximate; import org.usvm.api.Engine; -import runtime.LibSLRuntime; import sun.nio.ch.DirectBuffer; -/** - * CRC32Automaton for LSLCRC32 ~> java.util.zip.CRC32 - */ -@SuppressWarnings({"all", "unchecked"}) +@SuppressWarnings("unused") @Approximate(java.util.zip.CRC32.class) -public class CRC32 implements LibSLRuntime.Automaton, Checksum { +public class CRC32 implements Checksum { static { Engine.assume(true); } - private byte __$lsl_state = __$lsl_States.Allocated; - public int crc; - @LibSLRuntime.AutomatonConstructor - public CRC32(Void __$lsl_token, final byte p0, final int p1) { - this.__$lsl_state = p0; - this.crc = p1; - } - - @LibSLRuntime.AutomatonConstructor - public CRC32(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Allocated, 0); + public CRC32(int value) { + this.crc = value; } - /** - * [CONSTRUCTOR] CRC32Automaton::(CRC32) -> void - * Source: java/util/zip/CRC32.automaton.lsl:99 - */ public CRC32() { - this((Void) null); - Engine.assume(this.__$lsl_state == __$lsl_States.Allocated); - /* body */ { - } - this.__$lsl_state = __$lsl_States.Initialized; + this(0); } - /** - * [SUBROUTINE] CRC32Automaton::_updateCheck(array, int, int) -> void - * Source: java/util/zip/CRC32.automaton.lsl:50 - */ private void _updateCheck(byte[] b, int off, int len) { - /* body */ { - if (b == null) { - throw new NullPointerException(); - } - final int b_size = b.length; - if ((off < 0) || (len < 0) || (off > (b_size - len))) { - throw new ArrayIndexOutOfBoundsException(); - } - } + if (b == null) + throw new NullPointerException(); + + if (off < 0 || len < 0 || off > b.length - len) + throw new ArrayIndexOutOfBoundsException(); } - /** - * [SUBROUTINE] CRC32Automaton::_updateByteBuffer(long) -> int - * Source: java/util/zip/CRC32.automaton.lsl:61 - */ private int _updateByteBuffer(long addr) { - int result = 0; - /* body */ { - if (addr == 0L) { - throw new NullPointerException(); - } - result = Engine.makeSymbolicInt(); - } - return result; + if (addr == 0L) + throw new NullPointerException(); + + return Engine.makeSymbolicInt(); } - /** - * [SUBROUTINE] CRC32Automaton::_updateBytesCheck(array, int, int) -> void - * Source: java/util/zip/CRC32.automaton.lsl:75 - */ + @SuppressWarnings("ConstantValue") private void _updateBytesCheck(byte[] b, int off, int len) { - /* body */ { - if (len != 0) { - if (b != null) { - final int b_size = b.length; - Engine.assume(b_size >= 0); - if ((off < 0) || (off >= b_size)) { - throw new ArrayIndexOutOfBoundsException(off); - } - final int endIndex = (off + len) - 1; - if ((endIndex < 0) || (endIndex >= b_size)) { - throw new ArrayIndexOutOfBoundsException(endIndex); - } - } else { - throw new NullPointerException(); - } - } - } + if (len == 0) + return; + + if (b == null) + throw new NullPointerException(); + + int b_size = b.length; + Engine.assume(b_size >= 0); + if (off < 0 || off >= b_size) + throw new ArrayIndexOutOfBoundsException(off); + + int endIndex = off + len - 1; + if (endIndex < 0 || endIndex >= b_size) + throw new ArrayIndexOutOfBoundsException(endIndex); } - /** - * [FUNCTION] CRC32Automaton::getValue(CRC32) -> long - * Source: java/util/zip/CRC32.automaton.lsl:109 - */ public long getValue() { - long result = 0L; - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - result = ((long) this.crc) & 4294967295L; - } - return result; + return ((long) this.crc) & 4294967295L; } - /** - * [FUNCTION] CRC32Automaton::reset(CRC32) -> void - * Source: java/util/zip/CRC32.automaton.lsl:115 - */ public void reset() { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.crc = 0; - } + this.crc = 0; } - /** - * [FUNCTION] CRC32Automaton::update(CRC32, ByteBuffer) -> void - * Source: java/util/zip/CRC32.automaton.lsl:121 - */ + @SuppressWarnings({"ConstantValue", "PatternVariableCanBeUsed"}) public void update(ByteBuffer buffer) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int pos = buffer.position(); - final int limit = buffer.limit(); - if (pos > limit) { - throw new AssertionError(); - } - final int rem = limit - pos; - if (rem > 0) { - if ((buffer instanceof DirectBuffer)) { - final DirectBuffer directBuffer = ((DirectBuffer) buffer); - final long address = directBuffer.address(); - this.crc = _updateByteBuffer(address); - } else { - if (buffer.hasArray()) { - final int off = buffer.arrayOffset() + pos; - final byte[] bufferArray = buffer.array(); - _updateBytesCheck(bufferArray, off, rem); - this.crc = Engine.makeSymbolicInt(); - } else { - int len = 4096; - final int b_rem = buffer.remaining(); - if (b_rem < len) { - len = b_rem; - } - final byte[] b = new byte[len]; - final int b_size = b.length; - Engine.assume(b_size >= 0); - while (buffer.hasRemaining()) { - int length = buffer.remaining(); - if (b_size < length) { - length = b_size; - } - buffer.get(b, 0, length); - _updateCheck(b, 0, length); - _updateBytesCheck(b, 0, length); - } - ; - this.crc = Engine.makeSymbolicInt(); - } - } - buffer.position(limit); - } + int pos = buffer.position(); + int limit = buffer.limit(); + if (pos > limit) + throw new AssertionError(); + + int rem = limit - pos; + if (rem <= 0) + return; + + if (buffer instanceof DirectBuffer) { + DirectBuffer directBuffer = (DirectBuffer) buffer; + long address = directBuffer.address(); + this.crc = _updateByteBuffer(address); + buffer.position(limit); + return; } - } - /** - * [FUNCTION] CRC32Automaton::update(CRC32, array) -> void - * Source: java/util/zip/CRC32.automaton.lsl:178 - */ - public void update(byte[] b) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - final int len = b.length; - Engine.assume(len >= 0); - _updateCheck(b, 0, len); - _updateBytesCheck(b, 0, len); + if (buffer.hasArray()) { + int off = buffer.arrayOffset() + pos; + byte[] bufferArray = buffer.array(); + _updateBytesCheck(bufferArray, off, rem); this.crc = Engine.makeSymbolicInt(); + buffer.position(limit); + return; } - } - /** - * [FUNCTION] CRC32Automaton::update(CRC32, array, int, int) -> void - * Source: java/util/zip/CRC32.automaton.lsl:188 - */ - public void update(byte[] b, int off, int len) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - _updateCheck(b, off, len); - _updateBytesCheck(b, off, len); - this.crc = Engine.makeSymbolicInt(); + int len = 4096; + int b_rem = buffer.remaining(); + if (b_rem < len) + len = b_rem; + byte[] b = new byte[len]; + int b_size = b.length; + Engine.assume(b_size >= 0); + while (buffer.hasRemaining()) { + int length = buffer.remaining(); + if (b_size < length) + length = b_size; + buffer.get(b, 0, length); + _updateCheck(b, 0, length); + _updateBytesCheck(b, 0, length); } + this.crc = Engine.makeSymbolicInt(); + buffer.position(limit); } - /** - * [FUNCTION] CRC32Automaton::update(CRC32, int) -> void - * Source: java/util/zip/CRC32.automaton.lsl:196 - */ - public void update(int b) { - Engine.assume(this.__$lsl_state == __$lsl_States.Initialized); - /* body */ { - this.crc = Engine.makeSymbolicInt(); - } + @SuppressWarnings("ConstantValue") + public void update(byte[] b) { + int len = b.length; + Engine.assume(len >= 0); + _updateCheck(b, 0, len); + _updateBytesCheck(b, 0, len); + this.crc = Engine.makeSymbolicInt(); } - public static final class __$lsl_States { - public static final byte Allocated = (byte) 0; - - public static final byte Initialized = (byte) 1; + public void update(byte[] b, int off, int len) { + _updateCheck(b, off, len); + _updateBytesCheck(b, off, len); + this.crc = Engine.makeSymbolicInt(); } - @Approximate(CRC32.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } + public void update(int b) { + this.crc = Engine.makeSymbolicInt(); } } diff --git a/approximations/src/main/java/generated/libsl/utils/SymbolicInputStream.java b/approximations/src/main/java/generated/libsl/utils/SymbolicInputStream.java deleted file mode 100644 index 596b7801..00000000 --- a/approximations/src/main/java/generated/libsl/utils/SymbolicInputStream.java +++ /dev/null @@ -1,415 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - libsl/utils/SymbolicInputStream.lsl:15 -// - libsl/utils/SymbolicInputStream.main.lsl:16 -// -package generated.libsl.utils; - -import java.io.IOException; -import java.io.OutputStream; -import java.lang.IllegalArgumentException; -import java.lang.IndexOutOfBoundsException; -import java.lang.NullPointerException; -import java.lang.SuppressWarnings; -import java.lang.Void; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * SymbolicInputStreamAutomaton for SymbolicInputStream ~> libsl.utils.SymbolicInputStream - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.libsl.utils.SymbolicInputStream.class) -public final class SymbolicInputStream implements LibSLRuntime.Automaton { - static { - Engine.assume(true); - } - - public final int maxSize; - - public final boolean supportMarks; - - public volatile int dataSize; - - public volatile byte[] data; - - public volatile boolean closed; - - public volatile int pos; - - public int markPos; - - public int markLimit; - - @LibSLRuntime.AutomatonConstructor - public SymbolicInputStream(Void __$lsl_token, final byte p0, final int p1, final boolean p2, - final int p3, final byte[] p4, final boolean p5, final int p6, final int p7, - final int p8) { - this.maxSize = p1; - this.supportMarks = p2; - this.dataSize = p3; - this.data = p4; - this.closed = p5; - this.pos = p6; - this.markPos = p7; - this.markLimit = p8; - } - - @LibSLRuntime.AutomatonConstructor - public SymbolicInputStream(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, 0, false, -1, null, false, 0, -1, 0); - } - - /** - * [SUBROUTINE] SymbolicInputStreamAutomaton::_initBuffer() -> void - * Source: libsl/utils/SymbolicInputStream.main.lsl:57 - */ - private void _initBuffer() { - /* body */ { - if (this.data == null) { - Engine.assume(this.maxSize > 0); - final int newSize = Engine.makeSymbolicInt(); - Engine.assume(0 <= newSize); - Engine.assume(newSize < this.maxSize); - this.dataSize = newSize; - if (newSize == 0) { - this.data = new byte[0]; - } else { - this.data = Engine.makeSymbolicByteArray(newSize); - } - Engine.assume(this.data != null); - Engine.assume(this.dataSize == this.data.length); - } - } - } - - /** - * [SUBROUTINE] SymbolicInputStreamAutomaton::_checkFromIndexSize(int, int, int) -> void - * Source: libsl/utils/SymbolicInputStream.main.lsl:99 - */ - private void _checkFromIndexSize(int fromIndex, int size, int length) { - /* body */ { - if (((length | fromIndex | size) < 0) || (size > (length - fromIndex))) { - throw new IndexOutOfBoundsException("Range [%s, % void - * Source: libsl/utils/SymbolicInputStream.main.lsl:107 - */ - private void _updatePosition(int delta) { - /* body */ { - this.pos += delta; - if (this.markPos != -1) { - if (this.pos >= this.markLimit) { - this.markPos = -1; - } - } - } - } - - /** - * [SUBROUTINE] SymbolicInputStreamAutomaton::_moveDataTo(array, int, int) -> int - * Source: libsl/utils/SymbolicInputStream.main.lsl:117 - */ - private int _moveDataTo(byte[] dest, int offset, int count) { - int result = 0; - /* body */ { - result = 0; - final int available = this.dataSize - this.pos; - if (available != 0) { - Engine.assume(available > 0); - if (available < count) { - count = available; - } - LibSLRuntime.ArrayActions.copy(this.data, this.pos, dest, offset, count); - _updatePosition(count); - result = count; - } - } - return result; - } - - /** - * [FUNCTION] SymbolicInputStreamAutomaton::available(SymbolicInputStream) -> int - * Source: libsl/utils/SymbolicInputStream.main.lsl:143 - */ - public int available() throws java.io.IOException { - int result = 0; - /* body */ { - if (this.closed) { - throw new IOException("Stream closed"); - } - if (this.data == null) { - _initBuffer(); - } - Engine.assume(this.dataSize >= 0); - result = this.dataSize - this.pos; - } - return result; - } - - /** - * [FUNCTION] SymbolicInputStreamAutomaton::close(SymbolicInputStream) -> void - * Source: libsl/utils/SymbolicInputStream.main.lsl:151 - */ - public void close() throws java.io.IOException { - /* body */ { - this.closed = true; - } - } - - /** - * [FUNCTION] SymbolicInputStreamAutomaton::mark(SymbolicInputStream, int) -> void - * Source: libsl/utils/SymbolicInputStream.main.lsl:159 - */ - public void mark(int readlimit) { - /* body */ { - if (this.supportMarks) { - this.markPos = this.pos; - this.markLimit = readlimit; - } - } - } - - /** - * [FUNCTION] SymbolicInputStreamAutomaton::markSupported(SymbolicInputStream) -> boolean - * Source: libsl/utils/SymbolicInputStream.main.lsl:170 - */ - public boolean markSupported() { - boolean result = false; - /* body */ { - result = this.supportMarks; - } - return result; - } - - /** - * [FUNCTION] SymbolicInputStreamAutomaton::read(SymbolicInputStream) -> int - * Source: libsl/utils/SymbolicInputStream.main.lsl:176 - */ - public int read() throws java.io.IOException { - int result = 0; - /* body */ { - if (this.closed) { - throw new IOException("Stream closed"); - } - if (this.data == null) { - _initBuffer(); - } - Engine.assume(this.dataSize >= 0); - result = -1; - } - return result; - } - - /** - * [FUNCTION] SymbolicInputStreamAutomaton::read(SymbolicInputStream, array) -> int - * Source: libsl/utils/SymbolicInputStream.main.lsl:184 - */ - public int read(byte[] b) throws java.io.IOException { - int result = 0; - /* body */ { - final int len = b.length; - if (len == 0) { - result = 0; - } else { - Engine.assume(len > 0); - if (this.closed) { - throw new IOException("Stream closed"); - } - if (this.data == null) { - _initBuffer(); - } - Engine.assume(this.dataSize >= 0); - result = _moveDataTo(b, 0, len); - } - } - return result; - } - - /** - * [FUNCTION] SymbolicInputStreamAutomaton::read(SymbolicInputStream, array, int, int) -> int - * Source: libsl/utils/SymbolicInputStream.main.lsl:202 - */ - public int read(byte[] b, int off, int len) throws java.io.IOException { - int result = 0; - /* body */ { - _checkFromIndexSize(off, len, b.length); - if (len == 0) { - result = 0; - } else { - if (this.closed) { - throw new IOException("Stream closed"); - } - if (this.data == null) { - _initBuffer(); - } - Engine.assume(this.dataSize >= 0); - result = _moveDataTo(b, off, len); - } - } - return result; - } - - /** - * [FUNCTION] SymbolicInputStreamAutomaton::readAllBytes(SymbolicInputStream) -> array - * Source: libsl/utils/SymbolicInputStream.main.lsl:218 - */ - public byte[] readAllBytes() throws java.io.IOException { - byte[] result = null; - /* body */ { - if (this.closed) { - throw new IOException("Stream closed"); - } - if (this.data == null) { - _initBuffer(); - } - Engine.assume(this.dataSize >= 0); - if (this.pos == 0) { - result = this.data; - _updatePosition(this.dataSize); - } else { - if (this.pos == this.dataSize) { - result = new byte[0]; - } else { - final int len = this.dataSize - this.pos; - Engine.assume(len > 0); - result = new byte[len]; - _moveDataTo(result, 0, len); - } - } - } - return result; - } - - /** - * [FUNCTION] SymbolicInputStreamAutomaton::readNBytes(SymbolicInputStream, array, int, int) -> int - * Source: libsl/utils/SymbolicInputStream.main.lsl:243 - */ - public int readNBytes(byte[] b, int off, int len) throws java.io.IOException { - int result = 0; - /* body */ { - _checkFromIndexSize(off, len, b.length); - if (this.closed) { - throw new IOException("Stream closed"); - } - if (this.data == null) { - _initBuffer(); - } - Engine.assume(this.dataSize >= 0); - if (len == 0) { - result = 0; - } else { - result = _moveDataTo(b, off, len); - } - } - return result; - } - - /** - * [FUNCTION] SymbolicInputStreamAutomaton::readNBytes(SymbolicInputStream, int) -> array - * Source: libsl/utils/SymbolicInputStream.main.lsl:256 - */ - public byte[] readNBytes(int len) throws java.io.IOException { - byte[] result = null; - /* body */ { - if (len < 0) { - throw new IllegalArgumentException("len < 0"); - } - if (this.closed) { - throw new IOException("Stream closed"); - } - if (this.data == null) { - _initBuffer(); - } - Engine.assume(this.dataSize >= 0); - if (len == 0) { - result = new byte[0]; - } else { - result = new byte[len]; - _moveDataTo(result, 0, len); - } - } - return result; - } - - /** - * [FUNCTION] SymbolicInputStreamAutomaton::reset(SymbolicInputStream) -> void - * Source: libsl/utils/SymbolicInputStream.main.lsl:275 - */ - public void reset() throws java.io.IOException { - /* body */ { - if (this.supportMarks) { - if (this.closed) { - throw new IOException("Stream closed"); - } - if (this.data == null) { - _initBuffer(); - } - Engine.assume(this.dataSize >= 0); - if (this.markPos < 0) { - throw new IOException("Resetting to invalid mark"); - } - this.pos = this.markPos; - } else { - throw new IOException("mark/reset not supported"); - } - } - } - - /** - * [FUNCTION] SymbolicInputStreamAutomaton::skip(SymbolicInputStream, long) -> long - * Source: libsl/utils/SymbolicInputStream.main.lsl:294 - */ - public long skip(long n) throws java.io.IOException { - long result = 0L; - /* body */ { - if (this.closed) { - throw new IOException("Stream closed"); - } - if (this.data == null) { - _initBuffer(); - } - Engine.assume(this.dataSize >= 0); - result = 0L; - } - return result; - } - - /** - * [FUNCTION] SymbolicInputStreamAutomaton::transferTo(SymbolicInputStream, OutputStream) -> long - * Source: libsl/utils/SymbolicInputStream.main.lsl:302 - */ - public long transferTo(OutputStream output) throws java.io.IOException { - long result = 0L; - /* body */ { - if (output == null) { - throw new NullPointerException(); - } - if (this.closed) { - throw new IOException("Stream closed"); - } - if (this.data == null) { - _initBuffer(); - } - Engine.assume(this.dataSize >= 0); - result = 0L; - } - return result; - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(SymbolicInputStream.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/libsl/utils/SymbolicInputStreamImpl.java b/approximations/src/main/java/generated/libsl/utils/SymbolicInputStreamImpl.java new file mode 100644 index 00000000..82d1ad8e --- /dev/null +++ b/approximations/src/main/java/generated/libsl/utils/SymbolicInputStreamImpl.java @@ -0,0 +1,232 @@ +package generated.libsl.utils; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.IllegalArgumentException; +import java.lang.IndexOutOfBoundsException; +import java.lang.NullPointerException; +import java.lang.SuppressWarnings; + +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; +import runtime.LibSLRuntime; +import stub.libsl.utils.SymbolicInputStream; + +@Approximate(SymbolicInputStream.class) +public final class SymbolicInputStreamImpl extends InputStream { + + public final int maxSize; + + public final boolean supportMarks; + + public volatile int dataSize; + + public volatile byte[] data; + + public volatile boolean closed; + + public volatile int pos; + + public int markPos; + + public int markLimit; + + public SymbolicInputStreamImpl( + int maxSize, + boolean supportMarks, + int dataSize, + byte[] data, + boolean closed, + int pos, + int markPos, + int markLimit8 + ) { + this.maxSize = maxSize; + this.supportMarks = supportMarks; + this.dataSize = dataSize; + this.data = data; + this.closed = closed; + this.pos = pos; + this.markPos = markPos; + this.markLimit = markLimit8; + } + + private void _initBuffer() { + if (this.data != null) + return; + + Engine.assume(this.maxSize > 0); + int newSize = Engine.makeSymbolicInt(); + Engine.assume(0 <= newSize); + Engine.assume(newSize < this.maxSize); + this.dataSize = newSize; + if (newSize == 0) { + this.data = new byte[0]; + } else { + this.data = Engine.makeSymbolicByteArray(newSize); + } + Engine.assume(this.data != null); + Engine.assume(this.dataSize == this.data.length); + } + + public static void _checkFromIndexSize(int fromIndex, int size, int length) { + if (length < 0 || fromIndex < 0 || size < 0 || size > length - fromIndex) { + throw new IndexOutOfBoundsException("Range [%s, %= this.markLimit) + this.markPos = -1; + } + + private int _moveDataTo(byte[] dest, int offset, int count) { + int available = this.dataSize - this.pos; + if (available != 0) { + Engine.assume(available > 0); + if (available < count) + count = available; + LibSLRuntime.ArrayActions.copy(this.data, this.pos, dest, offset, count); + _updatePosition(count); + return count; + } + + return 0; + } + + public int available() throws java.io.IOException { + _checkClosed(); + _initBuffer(); + + Engine.assume(this.dataSize >= 0); + return this.dataSize - this.pos; + } + + public void close() throws java.io.IOException { + this.closed = true; + } + + public void mark(int readLimit) { + if (this.supportMarks) { + this.markPos = this.pos; + this.markLimit = readLimit; + } + } + + public boolean markSupported() { + return this.supportMarks; + } + + public int read() throws java.io.IOException { + _checkClosed(); + _initBuffer(); + + Engine.assume(this.dataSize >= 0); + return -1; + } + + @SuppressWarnings("ConstantValue") + public int read(@NotNull byte[] b) throws java.io.IOException { + int len = b.length; + if (len == 0) + return 0; + + Engine.assume(len > 0); + _checkClosed(); + _initBuffer(); + Engine.assume(this.dataSize >= 0); + return _moveDataTo(b, 0, len); + } + + public int read(@NotNull byte[] b, int off, int len) throws java.io.IOException { + _checkFromIndexSize(off, len, b.length); + if (len == 0) + return 0; + + _checkClosed(); + _initBuffer(); + Engine.assume(this.dataSize >= 0); + return _moveDataTo(b, off, len); + } + + public byte[] readAllBytes() throws java.io.IOException { + _checkClosed(); + _initBuffer(); + Engine.assume(this.dataSize >= 0); + if (this.pos == 0) { + _updatePosition(this.dataSize); + return this.data; + } + + if (this.pos == this.dataSize) + return new byte[0]; + + int len = this.dataSize - this.pos; + Engine.assume(len > 0); + byte[] result = new byte[len]; + _moveDataTo(result, 0, len); + return result; + } + + public int readNBytes(byte[] b, int off, int len) throws java.io.IOException { + _checkFromIndexSize(off, len, b.length); + _checkClosed(); + _initBuffer(); + Engine.assume(this.dataSize >= 0); + if (len == 0) + return 0; + + return _moveDataTo(b, off, len); + } + + public byte[] readNBytes(int len) throws java.io.IOException { + if (len < 0) + throw new IllegalArgumentException("len < 0"); + _checkClosed(); + _initBuffer(); + Engine.assume(this.dataSize >= 0); + if (len == 0) + return new byte[0]; + + byte[] result = new byte[len]; + _moveDataTo(result, 0, len); + return result; + } + + public void reset() throws java.io.IOException { + if (!this.supportMarks) + throw new IOException("mark/reset not supported"); + + _checkClosed(); + _initBuffer(); + Engine.assume(this.dataSize >= 0); + if (this.markPos < 0) + throw new IOException("Resetting to invalid mark"); + this.pos = this.markPos; + } + + public long skip(long n) throws java.io.IOException { + _checkClosed(); + _initBuffer(); + Engine.assume(this.dataSize >= 0); + return 0L; + } + + public long transferTo(OutputStream output) throws java.io.IOException { + if (output == null) + throw new NullPointerException(); + _checkClosed(); + _initBuffer(); + Engine.assume(this.dataSize >= 0); + return 0L; + } +} diff --git a/approximations/src/main/java/generated/libsl/utils/VoidInputStream.java b/approximations/src/main/java/generated/libsl/utils/VoidInputStream.java deleted file mode 100644 index 605d3fbe..00000000 --- a/approximations/src/main/java/generated/libsl/utils/VoidInputStream.java +++ /dev/null @@ -1,256 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - libsl/utils/VoidInputStream.lsl:15 -// - libsl/utils/VoidInputStream.main.lsl:16 -// -package generated.libsl.utils; - -import java.io.IOException; -import java.io.OutputStream; -import java.lang.IllegalArgumentException; -import java.lang.IndexOutOfBoundsException; -import java.lang.NullPointerException; -import java.lang.SuppressWarnings; -import java.lang.Void; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * VoidInputStreamAutomaton for VoidInputStream ~> libsl.utils.VoidInputStream - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.libsl.utils.VoidInputStream.class) -public final class VoidInputStream implements LibSLRuntime.Automaton { - static { - Engine.assume(true); - } - - public volatile boolean closed; - - @LibSLRuntime.AutomatonConstructor - public VoidInputStream(Void __$lsl_token, final byte p0, final boolean p1) { - this.closed = p1; - } - - @LibSLRuntime.AutomatonConstructor - public VoidInputStream(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, false); - } - - /** - * [SUBROUTINE] VoidInputStreamAutomaton::_checkFromIndexSize(int, int, int) -> void - * Source: libsl/utils/VoidInputStream.main.lsl:55 - */ - private void _checkFromIndexSize(int fromIndex, int size, int length) { - /* body */ { - if (((length | fromIndex | size) < 0) || (size > (length - fromIndex))) { - throw new IndexOutOfBoundsException("Range [%s, % int - * Source: libsl/utils/VoidInputStream.main.lsl:69 - */ - public int available() throws java.io.IOException { - int result = 0; - /* body */ { - if (this.closed) { - throw new IOException("Stream closed"); - } - result = 0; - } - return result; - } - - /** - * [FUNCTION] VoidInputStreamAutomaton::close(VoidInputStream) -> void - * Source: libsl/utils/VoidInputStream.main.lsl:77 - */ - public void close() throws java.io.IOException { - /* body */ { - this.closed = true; - } - } - - /** - * [FUNCTION] VoidInputStreamAutomaton::mark(VoidInputStream, int) -> void - * Source: libsl/utils/VoidInputStream.main.lsl:85 - */ - public synchronized void mark(int readlimit) { - /* body */ { - } - } - - /** - * [FUNCTION] VoidInputStreamAutomaton::markSupported(VoidInputStream) -> boolean - * Source: libsl/utils/VoidInputStream.main.lsl:92 - */ - public boolean markSupported() { - boolean result = false; - /* body */ { - result = false; - } - return result; - } - - /** - * [FUNCTION] VoidInputStreamAutomaton::read(VoidInputStream) -> int - * Source: libsl/utils/VoidInputStream.main.lsl:98 - */ - public int read() throws java.io.IOException { - int result = 0; - /* body */ { - if (this.closed) { - throw new IOException("Stream closed"); - } - result = -1; - } - return result; - } - - /** - * [FUNCTION] VoidInputStreamAutomaton::read(VoidInputStream, array) -> int - * Source: libsl/utils/VoidInputStream.main.lsl:106 - */ - public int read(byte[] b) throws java.io.IOException { - int result = 0; - /* body */ { - if (b.length == 0) { - result = 0; - } else { - if (this.closed) { - throw new IOException("Stream closed"); - } - result = -1; - } - } - return result; - } - - /** - * [FUNCTION] VoidInputStreamAutomaton::read(VoidInputStream, array, int, int) -> int - * Source: libsl/utils/VoidInputStream.main.lsl:122 - */ - public int read(byte[] b, int off, int len) throws java.io.IOException { - int result = 0; - /* body */ { - _checkFromIndexSize(off, len, b.length); - if (len == 0) { - result = 0; - } else { - if (this.closed) { - throw new IOException("Stream closed"); - } - result = -1; - } - } - return result; - } - - /** - * [FUNCTION] VoidInputStreamAutomaton::readAllBytes(VoidInputStream) -> array - * Source: libsl/utils/VoidInputStream.main.lsl:138 - */ - public byte[] readAllBytes() throws java.io.IOException { - byte[] result = null; - /* body */ { - if (this.closed) { - throw new IOException("Stream closed"); - } - result = new byte[0]; - } - return result; - } - - /** - * [FUNCTION] VoidInputStreamAutomaton::readNBytes(VoidInputStream, array, int, int) -> int - * Source: libsl/utils/VoidInputStream.main.lsl:146 - */ - public int readNBytes(byte[] b, int off, int len) throws java.io.IOException { - int result = 0; - /* body */ { - _checkFromIndexSize(off, len, b.length); - if (this.closed) { - throw new IOException("Stream closed"); - } - result = 0; - } - return result; - } - - /** - * [FUNCTION] VoidInputStreamAutomaton::readNBytes(VoidInputStream, int) -> array - * Source: libsl/utils/VoidInputStream.main.lsl:155 - */ - public byte[] readNBytes(int len) throws java.io.IOException { - byte[] result = null; - /* body */ { - if (len < 0) { - throw new IllegalArgumentException("len < 0"); - } else { - if (this.closed) { - throw new IOException("Stream closed"); - } - result = new byte[0]; - } - } - return result; - } - - /** - * [FUNCTION] VoidInputStreamAutomaton::reset(VoidInputStream) -> void - * Source: libsl/utils/VoidInputStream.main.lsl:170 - */ - public synchronized void reset() throws java.io.IOException { - /* body */ { - throw new IOException("mark/reset not supported"); - } - } - - /** - * [FUNCTION] VoidInputStreamAutomaton::skip(VoidInputStream, long) -> long - * Source: libsl/utils/VoidInputStream.main.lsl:178 - */ - public long skip(long n) throws java.io.IOException { - long result = 0L; - /* body */ { - if (this.closed) { - throw new IOException("Stream closed"); - } - result = 0L; - } - return result; - } - - /** - * [FUNCTION] VoidInputStreamAutomaton::transferTo(VoidInputStream, OutputStream) -> long - * Source: libsl/utils/VoidInputStream.main.lsl:186 - */ - public long transferTo(OutputStream output) throws java.io.IOException { - long result = 0L; - /* body */ { - if (output == null) { - throw new NullPointerException(); - } - if (this.closed) { - throw new IOException("Stream closed"); - } - result = 0L; - } - return result; - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(VoidInputStream.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/libsl/utils/VoidInputStreamImpl.java b/approximations/src/main/java/generated/libsl/utils/VoidInputStreamImpl.java new file mode 100644 index 00000000..9e768177 --- /dev/null +++ b/approximations/src/main/java/generated/libsl/utils/VoidInputStreamImpl.java @@ -0,0 +1,116 @@ +package generated.libsl.utils; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.IllegalArgumentException; +import java.lang.NullPointerException; +import java.lang.SuppressWarnings; + +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import stub.libsl.utils.VoidInputStream; + +@SuppressWarnings("unused") +@Approximate(VoidInputStream.class) +public final class VoidInputStreamImpl extends InputStream { + + public volatile boolean closed; + + public VoidInputStreamImpl(boolean p1) { + this.closed = p1; + } + + public int available() throws java.io.IOException { + if (this.closed) + throw new IOException("Stream closed"); + + return 0; + } + + public void close() throws java.io.IOException { + this.closed = true; + } + + public synchronized void mark(int readLimit) { + } + + @SuppressWarnings("RedundantMethodOverride") + public boolean markSupported() { + return false; + } + + public int read() throws java.io.IOException { + if (this.closed) + throw new IOException("Stream closed"); + + return -1; + } + + public int read(@NotNull byte[] b) throws java.io.IOException { + if (b.length == 0) + return 0; + + if (this.closed) + throw new IOException("Stream closed"); + + return -1; + } + + public int read(@NotNull byte[] b, int off, int len) throws java.io.IOException { + SymbolicInputStreamImpl._checkFromIndexSize(off, len, b.length); + if (len == 0) + return 0; + + if (this.closed) + throw new IOException("Stream closed"); + + return -1; + } + + public byte[] readAllBytes() throws java.io.IOException { + if (this.closed) + throw new IOException("Stream closed"); + + return new byte[0]; + } + + public int readNBytes(byte[] b, int off, int len) throws java.io.IOException { + SymbolicInputStreamImpl._checkFromIndexSize(off, len, b.length); + if (this.closed) + throw new IOException("Stream closed"); + + return 0; + } + + public byte[] readNBytes(int len) throws java.io.IOException { + if (len < 0) + throw new IllegalArgumentException("len < 0"); + + if (this.closed) + throw new IOException("Stream closed"); + + return new byte[0]; + } + + public synchronized void reset() throws java.io.IOException { + throw new IOException("mark/reset not supported"); + } + + public long skip(long n) throws java.io.IOException { + if (this.closed) + throw new IOException("Stream closed"); + + return 0L; + } + + public long transferTo(OutputStream output) throws java.io.IOException { + if (output == null) + throw new NullPointerException(); + + if (this.closed) + throw new IOException("Stream closed"); + + return 0L; + } +} diff --git a/approximations/src/main/java/generated/libsl/utils/VoidOutputStream.java b/approximations/src/main/java/generated/libsl/utils/VoidOutputStream.java deleted file mode 100644 index 77997694..00000000 --- a/approximations/src/main/java/generated/libsl/utils/VoidOutputStream.java +++ /dev/null @@ -1,120 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - libsl/utils/VoidOutputStream.lsl:15 -// - libsl/utils/VoidOutputStream.main.lsl:16 -// -package generated.libsl.utils; - -import java.io.IOException; -import java.lang.IndexOutOfBoundsException; -import java.lang.NullPointerException; -import java.lang.SuppressWarnings; -import java.lang.Void; -import org.jacodb.approximation.annotation.Approximate; -import org.usvm.api.Engine; -import runtime.LibSLRuntime; - -/** - * VoidOutputStreamAutomaton for VoidOutputStream ~> libsl.utils.VoidOutputStream - */ -@SuppressWarnings({"all", "unchecked"}) -@Approximate(stub.libsl.utils.VoidOutputStream.class) -public final class VoidOutputStream implements LibSLRuntime.Automaton { - static { - Engine.assume(true); - } - - public volatile boolean closed; - - @LibSLRuntime.AutomatonConstructor - public VoidOutputStream(Void __$lsl_token, final byte p0, final boolean p1) { - this.closed = p1; - } - - @LibSLRuntime.AutomatonConstructor - public VoidOutputStream(final Void __$lsl_token) { - this(__$lsl_token, __$lsl_States.Initialized, false); - } - - /** - * [SUBROUTINE] VoidOutputStreamAutomaton::_checkFromIndexSize(int, int, int) -> void - * Source: libsl/utils/VoidOutputStream.main.lsl:47 - */ - private void _checkFromIndexSize(int fromIndex, int size, int length) { - /* body */ { - if (((length | fromIndex | size) < 0) || (size > (length - fromIndex))) { - throw new IndexOutOfBoundsException("Range [%s, % void - * Source: libsl/utils/VoidOutputStream.main.lsl:61 - */ - public void close() { - /* body */ { - this.closed = true; - } - } - - /** - * [FUNCTION] VoidOutputStreamAutomaton::flush(VoidOutputStream) -> void - * Source: libsl/utils/VoidOutputStream.main.lsl:67 - */ - public void flush() throws java.io.IOException { - /* body */ { - } - } - - /** - * [FUNCTION] VoidOutputStreamAutomaton::write(VoidOutputStream, array) -> void - * Source: libsl/utils/VoidOutputStream.main.lsl:75 - */ - public void write(byte[] b) throws java.io.IOException { - /* body */ { - if (b == null) { - throw new NullPointerException(); - } - if (this.closed) { - throw new IOException("Stream closed"); - } - } - } - - /** - * [FUNCTION] VoidOutputStreamAutomaton::write(VoidOutputStream, array, int, int) -> void - * Source: libsl/utils/VoidOutputStream.main.lsl:86 - */ - public void write(byte[] b, int off, int len) throws java.io.IOException { - /* body */ { - _checkFromIndexSize(off, len, b.length); - if (this.closed) { - throw new IOException("Stream closed"); - } - } - } - - /** - * [FUNCTION] VoidOutputStreamAutomaton::write(VoidOutputStream, int) -> void - * Source: libsl/utils/VoidOutputStream.main.lsl:94 - */ - public void write(int b) throws java.io.IOException { - /* body */ { - if (this.closed) { - throw new IOException("Stream closed"); - } - } - } - - public static final class __$lsl_States { - public static final byte Initialized = (byte) 0; - } - - @Approximate(VoidOutputStream.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } -} diff --git a/approximations/src/main/java/generated/libsl/utils/VoidOutputStreamImpl.java b/approximations/src/main/java/generated/libsl/utils/VoidOutputStreamImpl.java new file mode 100644 index 00000000..76c54f31 --- /dev/null +++ b/approximations/src/main/java/generated/libsl/utils/VoidOutputStreamImpl.java @@ -0,0 +1,47 @@ +package generated.libsl.utils; + +import java.io.IOException; +import java.io.OutputStream; +import java.lang.NullPointerException; +import java.lang.SuppressWarnings; + +import org.jacodb.approximation.annotation.Approximate; +import org.jetbrains.annotations.NotNull; +import stub.libsl.utils.VoidOutputStream; + +@SuppressWarnings("unused") +@Approximate(VoidOutputStream.class) +public final class VoidOutputStreamImpl extends OutputStream { + + public volatile boolean closed; + + public VoidOutputStreamImpl(boolean p1) { + this.closed = p1; + } + + public void close() { + this.closed = true; + } + + @SuppressWarnings({"RedundantMethodOverride", "RedundantThrows"}) + public void flush() throws java.io.IOException { } + + @SuppressWarnings("ConstantValue") + public void write(@NotNull byte[] b) throws java.io.IOException { + if (b == null) + throw new NullPointerException(); + if (this.closed) + throw new IOException("Stream closed"); + } + + public void write(@NotNull byte[] b, int off, int len) throws java.io.IOException { + SymbolicInputStreamImpl._checkFromIndexSize(off, len, b.length); + if (this.closed) + throw new IOException("Stream closed"); + } + + public void write(int b) throws java.io.IOException { + if (this.closed) + throw new IOException("Stream closed"); + } +} diff --git a/approximations/src/main/java/generated/org/apache/commons/logging/LogFactoryImpl.java b/approximations/src/main/java/generated/org/apache/commons/logging/LogFactoryImpl.java new file mode 100644 index 00000000..7ca32cea --- /dev/null +++ b/approximations/src/main/java/generated/org/apache/commons/logging/LogFactoryImpl.java @@ -0,0 +1,17 @@ +package generated.org.apache.commons.logging; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.impl.NoOpLog; +import org.jacodb.approximation.annotation.Approximate; + +@Approximate(org.apache.commons.logging.LogFactory.class) +public abstract class LogFactoryImpl { + + public static Log getLog(Class clazz) { + return new NoOpLog(); + } + + public static Log getLog(String name) { + return new NoOpLog(); + } +} diff --git a/approximations/src/main/java/generated/org/apache/commons/logging/LogImpl.java b/approximations/src/main/java/generated/org/apache/commons/logging/LogImpl.java new file mode 100644 index 00000000..10629579 --- /dev/null +++ b/approximations/src/main/java/generated/org/apache/commons/logging/LogImpl.java @@ -0,0 +1,56 @@ +package generated.org.apache.commons.logging; + +import org.jacodb.approximation.annotation.Approximate; + +@SuppressWarnings("unused") +@Approximate(org.apache.commons.logging.Log.class) +public class LogImpl { + + final boolean isFatalEnabled() { + return false; + } + + final boolean isErrorEnabled() { + return false; + } + + final boolean isWarnEnabled() { + return false; + } + + final boolean isInfoEnabled() { + return false; + } + + final boolean isDebugEnabled() { + return false; + } + + final boolean isTraceEnabled() { + return false; + } + + final void fatal(Object message) { } + + final void fatal(Object message, Throwable t) { } + + final void error(Object message) { } + + final void error(Object message, Throwable t) { } + + final void warn(Object message) { } + + final void warn(Object message, Throwable t) { } + + final void info(Object message) { } + + final void info(Object message, Throwable t) { } + + final void debug(Object message) { } + + final void debug(Object message, Throwable t) { } + + final void trace(Object message) { } + + final void trace(Object message, Throwable t) { } +} diff --git a/approximations/src/main/java/generated/org/slf4j/LogFactoryImpl.java b/approximations/src/main/java/generated/org/slf4j/LogFactoryImpl.java new file mode 100644 index 00000000..b7f8272d --- /dev/null +++ b/approximations/src/main/java/generated/org/slf4j/LogFactoryImpl.java @@ -0,0 +1,18 @@ +package generated.org.slf4j; + +import org.jacodb.approximation.annotation.Approximate; +import org.slf4j.Logger; +import org.slf4j.helpers.NOPLogger; + +@SuppressWarnings("unused") +@Approximate(org.slf4j.LoggerFactory.class) +public abstract class LogFactoryImpl { + + public static Logger getLogger(String name) { + return NOPLogger.NOP_LOGGER; + } + + public static Logger getLogger(Class clazz) { + return NOPLogger.NOP_LOGGER; + } +} diff --git a/approximations/src/main/java/generated/org/springframework/boot/ClassUtilsImpl.java b/approximations/src/main/java/generated/org/springframework/boot/ClassUtilsImpl.java new file mode 100644 index 00000000..2828168e --- /dev/null +++ b/approximations/src/main/java/generated/org/springframework/boot/ClassUtilsImpl.java @@ -0,0 +1,19 @@ +package generated.org.springframework.boot; + +import org.jacodb.approximation.annotation.Approximate; +import org.springframework.util.ClassUtils; + +@Approximate(ClassUtils.class) +public abstract class ClassUtilsImpl { + + private static String getMainPackageName() { + throw new IllegalStateException("'getMainPackageName' should be approximated"); + } + + public static String getPackageName(Class clazz) { + if (clazz.getName().equals("StartSpringTestClass")) + return ClassUtilsImpl.getMainPackageName(); + + return clazz.getPackageName(); + } +} diff --git a/approximations/src/main/java/generated/org/springframework/boot/ErrorsMethodArgumentResolverImpl.java b/approximations/src/main/java/generated/org/springframework/boot/ErrorsMethodArgumentResolverImpl.java new file mode 100644 index 00000000..475effc1 --- /dev/null +++ b/approximations/src/main/java/generated/org/springframework/boot/ErrorsMethodArgumentResolverImpl.java @@ -0,0 +1,28 @@ +package generated.org.springframework.boot; + +import org.jacodb.approximation.annotation.Approximate; +import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; +import org.springframework.ui.ModelMap; +import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; +import org.springframework.web.bind.support.WebDataBinderFactory; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.method.support.ModelAndViewContainer; + +@SuppressWarnings("unused") +@Approximate(org.springframework.web.method.annotation.ErrorsMethodArgumentResolver.class) +public class ErrorsMethodArgumentResolverImpl { + + @SuppressWarnings("RedundantThrows") + public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { + Assert.state(mavContainer != null, "Errors/BindingResult argument only supported on regular handler methods"); + ModelMap model = mavContainer.getModel(); + String lastKey = CollectionUtils.lastElement(model.keySet()); + if (lastKey != null) { + return model.get(lastKey); + } else { + throw new IllegalStateException("An Errors/BindingResult argument is expected to be declared immediately after the model attribute, the @RequestBody or the @RequestPart arguments to which they apply: " + parameter.getMethod()); + } + } +} diff --git a/approximations/src/main/java/generated/org/springframework/boot/MergedContextConfigurationImpl.java b/approximations/src/main/java/generated/org/springframework/boot/MergedContextConfigurationImpl.java new file mode 100644 index 00000000..5a183dac --- /dev/null +++ b/approximations/src/main/java/generated/org/springframework/boot/MergedContextConfigurationImpl.java @@ -0,0 +1,26 @@ +package generated.org.springframework.boot; + +import org.jacodb.approximation.annotation.Approximate; +import org.springframework.lang.Nullable; +import org.springframework.test.context.ContextCustomizer; +import org.springframework.test.context.MergedContextConfiguration; + +import java.util.Collections; +import java.util.Set; + +@Approximate(MergedContextConfiguration.class) +public class MergedContextConfigurationImpl { + + private static final Set EMPTY_CONTEXT_CUSTOMIZERS = Collections.emptySet(); + + private static Set processContextCustomizers( + @Nullable Set contextCustomizers + ) { + if (contextCustomizers == null) + return EMPTY_CONTEXT_CUSTOMIZERS; + + contextCustomizers.removeIf(it -> it.getClass().getName().contains("TypeExcludeFiltersContextCustomizer")); + + return contextCustomizers; + } +} diff --git a/approximations/src/main/java/generated/org/springframework/boot/PathVariableMethodArgumentResolverImpl.java b/approximations/src/main/java/generated/org/springframework/boot/PathVariableMethodArgumentResolverImpl.java new file mode 100644 index 00000000..91da2d61 --- /dev/null +++ b/approximations/src/main/java/generated/org/springframework/boot/PathVariableMethodArgumentResolverImpl.java @@ -0,0 +1,20 @@ +package generated.org.springframework.boot; + +import org.jacodb.approximation.annotation.Approximate; +import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; +import org.springframework.web.bind.support.WebDataBinderFactory; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.method.support.ModelAndViewContainer; + +import static generated.org.springframework.boot.SymbolicValueFactory.createSymbolic; + +@Approximate(org.springframework.web.servlet.mvc.method.annotation.PathVariableMethodArgumentResolver.class) +public class PathVariableMethodArgumentResolverImpl { + + public final Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { + Class paramType = parameter.getParameterType(); + return createSymbolic(paramType); + } +} diff --git a/approximations/src/main/java/generated/org/springframework/boot/RequestParamMethodArgumentResolverImpl.java b/approximations/src/main/java/generated/org/springframework/boot/RequestParamMethodArgumentResolverImpl.java new file mode 100644 index 00000000..6751c96a --- /dev/null +++ b/approximations/src/main/java/generated/org/springframework/boot/RequestParamMethodArgumentResolverImpl.java @@ -0,0 +1,20 @@ +package generated.org.springframework.boot; + +import org.jacodb.approximation.annotation.Approximate; +import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; +import org.springframework.web.bind.support.WebDataBinderFactory; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.method.support.ModelAndViewContainer; + +import static generated.org.springframework.boot.SymbolicValueFactory.createSymbolic; + +@Approximate(org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.class) +public class RequestParamMethodArgumentResolverImpl { + + public final Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { + Class paramType = parameter.getParameterType(); + return createSymbolic(paramType); + } +} diff --git a/approximations/src/main/java/generated/org/springframework/boot/SpringApplicationImpl.java b/approximations/src/main/java/generated/org/springframework/boot/SpringApplicationImpl.java new file mode 100644 index 00000000..82527267 --- /dev/null +++ b/approximations/src/main/java/generated/org/springframework/boot/SpringApplicationImpl.java @@ -0,0 +1,82 @@ +package generated.org.springframework.boot; + +import jakarta.servlet.Filter; +import org.jacodb.approximation.annotation.Approximate; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationContextFactory; +import org.springframework.boot.context.logging.LoggingApplicationListener; +import org.springframework.context.ApplicationListener; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import java.util.*; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; + +@Approximate(org.springframework.boot.SpringApplication.class) +public class SpringApplicationImpl { + + private List> listeners; + + private ApplicationContextFactory applicationContextFactory = ApplicationContextFactory.DEFAULT; + + private boolean registerShutdownHook = true; + + private Map>> allControllerPaths() { + return new HashMap<>(); + } + + private void internalLog(String message) { } + + protected void afterRefresh(ConfigurableApplicationContext context, ApplicationArguments args) { + startAnalysis(); + Object[] beans = context.getBeansOfType(Filter.class).values().toArray(); + Filter[] filters = Arrays.copyOf(beans, beans.length, Filter[].class); + DefaultMockMvcBuilder builder = MockMvcBuilders.webAppContextSetup((WebApplicationContext) context); + for (Filter filter : filters) { + builder.addFilter(filter); + } + MockMvc mockMvc = builder.build(); + Map>> allPaths = allControllerPaths(); + try { + for (String controllerName : allPaths.keySet()) { + internalLog("[USVM] starting to analyze controller " + controllerName); + Map> paths = allPaths.get(controllerName); + for (String path : paths.keySet()) { + internalLog("[USVM] starting to analyze path " + path); + + List properties = paths.get(path); + String kind = (String) properties.get(0); + Integer paramCount = (Integer) properties.get(1); + Object[] pathArgs = new Object[paramCount]; + if (kind.equals("get")) + mockMvc.perform(get(path, pathArgs)); + if (kind.equals("post")) + mockMvc.perform(post(path, pathArgs)); + if (kind.equals("put")) + mockMvc.perform(put(path, pathArgs)); + if (kind.equals("delete")) + mockMvc.perform(delete(path, pathArgs)); + if (kind.equals("patch")) + mockMvc.perform(patch(path, pathArgs)); + + internalLog("[USVM] end of path analysis " + path); + } + internalLog("[USVM] end of controller analysis " + controllerName); + } + } catch (Throwable e) { + internalLog("[USVM] analysis finished with exception"); + } + } + + private void startAnalysis() { } + + public void setListeners(Collection> listeners) { + registerShutdownHook = false; + listeners.removeIf(it -> it instanceof LoggingApplicationListener); + this.listeners = new ArrayList<>(listeners); + } +} diff --git a/approximations/src/main/java/generated/org/springframework/boot/StartSpring.java b/approximations/src/main/java/generated/org/springframework/boot/StartSpring.java new file mode 100644 index 00000000..41c9969a --- /dev/null +++ b/approximations/src/main/java/generated/org/springframework/boot/StartSpring.java @@ -0,0 +1,11 @@ +package generated.org.springframework.boot; + +import org.springframework.test.context.TestContextManager; + +public class StartSpring { + + public static void startSpring() { + TestContextManager b = new TestContextManager(TestClass.class); + b.getTestContext().getApplicationContext(); + } +} diff --git a/approximations/src/main/java/generated/org/springframework/boot/SymbolicValueFactory.java b/approximations/src/main/java/generated/org/springframework/boot/SymbolicValueFactory.java new file mode 100644 index 00000000..57055eff --- /dev/null +++ b/approximations/src/main/java/generated/org/springframework/boot/SymbolicValueFactory.java @@ -0,0 +1,24 @@ +package generated.org.springframework.boot; + +import org.usvm.api.Engine; + +public class SymbolicValueFactory { + public static Object createSymbolic(Class type) { + if (type == boolean.class) + return Engine.makeSymbolicBoolean(); + if (type == int.class) + return Engine.makeSymbolicInt(); + if (type == long.class) + return Engine.makeSymbolicLong(); + if (type == float.class) + return Engine.makeSymbolicFloat(); + if (type == byte.class) + return Engine.makeSymbolicByte(); + if (type == char.class) + return Engine.makeSymbolicChar(); + if (type == short.class) + return Engine.makeSymbolicShort(); + + return Engine.makeNullableSymbolic(type); + } +} diff --git a/approximations/src/main/java/generated/org/springframework/boot/TestClass.java b/approximations/src/main/java/generated/org/springframework/boot/TestClass.java new file mode 100644 index 00000000..d66f59e8 --- /dev/null +++ b/approximations/src/main/java/generated/org/springframework/boot/TestClass.java @@ -0,0 +1,12 @@ +package generated.org.springframework.boot; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.test.web.servlet.MockMvc; + +@WebMvcTest +public class TestClass { + + @Autowired + private MockMvc mockMvc; +} diff --git a/approximations/src/main/java/generated/org/springframework/boot/TestContextManagerImpl.java b/approximations/src/main/java/generated/org/springframework/boot/TestContextManagerImpl.java new file mode 100644 index 00000000..f50b2741 --- /dev/null +++ b/approximations/src/main/java/generated/org/springframework/boot/TestContextManagerImpl.java @@ -0,0 +1,57 @@ +package generated.org.springframework.boot; + +import org.jacodb.approximation.annotation.Approximate; +import org.springframework.test.context.TestContext; +import org.springframework.test.context.TestContextBootstrapper; +import org.springframework.test.context.TestContextManager; +import org.springframework.test.context.TestExecutionListener; +import org.springframework.util.ClassUtils; +import org.springframework.util.ReflectionUtils; + +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +@Approximate(TestContextManager.class) +public class TestContextManagerImpl { + + private final TestContext testContext; + + private final List testExecutionListeners = new ArrayList<>(8); + + private static TestContext copyTestContext(TestContext testContext) { + Constructor constructor = + ClassUtils.getConstructorIfAvailable(testContext.getClass(), testContext.getClass()); + + if (constructor != null) { + try { + ReflectionUtils.makeAccessible(constructor); + return constructor.newInstance(testContext); + } + catch (Exception ignored) { + } + } + + // Fallback to original instance + return testContext; + } + + public TestContextManagerImpl(TestContextBootstrapper testContextBootstrapper) { + this.testContext = testContextBootstrapper.buildTestContext(); + registerTestExecutionListeners(testContextBootstrapper.getTestExecutionListeners()); + } + + public final TestContext getTestContext() { + return this.testContext; + } + + public void registerTestExecutionListeners(List testExecutionListeners) { + registerTestExecutionListeners(testExecutionListeners.toArray(new TestExecutionListener[0])); + } + + public void registerTestExecutionListeners(TestExecutionListener... testExecutionListeners) { + Collections.addAll(this.testExecutionListeners, testExecutionListeners); + } + +} diff --git a/approximations/src/main/java/generated/runtime/LibSLGlobals.java b/approximations/src/main/java/generated/runtime/LibSLGlobals.java index ab17ae0d..a567f762 100644 --- a/approximations/src/main/java/generated/runtime/LibSLGlobals.java +++ b/approximations/src/main/java/generated/runtime/LibSLGlobals.java @@ -1,129 +1,57 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - *global variables* -// package generated.runtime; import java.lang.Object; -import java.lang.Void; + import org.jacodb.approximation.annotation.Approximate; import org.usvm.api.Engine; @Approximate(runtime.LibSLGlobals.class) public final class LibSLGlobals { - /** - * Source: java/io/Console.lsl:22 - */ + public static final boolean CONSOLE_IS_TTY; - /** - * Source: java/lang/Character.lsl:53 - */ public static final int MAX_CODE_POINT; - /** - * Source: java/lang/Character.lsl:54 - */ public static final int MIN_CODE_POINT; - /** - * Source: java/lang/Character.lsl:56 - */ public static final int MIN_HIGH_SURROGATE; - /** - * Source: java/lang/Character.lsl:55 - */ public static final int MIN_LOW_SURROGATE; - /** - * Source: java/lang/Character.lsl:57 - */ public static final int MIN_SUPPLEMENTARY_CODE_POINT; - /** - * Source: java/util/Random.lsl:26 - */ public static final int RANDOM_STREAM_SIZE_MAX; - /** - * Source: java/lang/Object.lsl:25 - */ public static final Object SOMETHING; - /** - * Source: java/util/Spliterator.lsl:42 - */ public static final int SPLITERATOR_CONCURRENT; - /** - * Source: java/util/Spliterator.lsl:36 - */ public static final int SPLITERATOR_DISTINCT; - /** - * Source: java/util/Spliterator.lsl:41 - */ public static final int SPLITERATOR_IMMUTABLE; - /** - * Source: java/util/Spliterator.lsl:40 - */ public static final int SPLITERATOR_NONNULL; - /** - * Source: java/util/Spliterator.lsl:38 - */ public static final int SPLITERATOR_ORDERED; - /** - * Source: java/util/Spliterator.lsl:39 - */ public static final int SPLITERATOR_SIZED; - /** - * Source: java/util/Spliterator.lsl:37 - */ public static final int SPLITERATOR_SORTED; - /** - * Source: java/util/Spliterator.lsl:43 - */ public static final int SPLITERATOR_SUBSIZED; - /** - * Source: java/lang/System.lsl:79 - */ public static final boolean SYSTEM_IS_MAC; - /** - * Source: java/lang/System.lsl:80 - */ public static final boolean SYSTEM_IS_WINDOWS; - /** - * Source: jdk/internal/misc/VM.lsl:42 - */ public static final int VM_JAVA_LANG_SYSTEM_INITED; - /** - * Source: jdk/internal/misc/VM.lsl:43 - */ public static final int VM_MODULE_SYSTEM_INITED; - /** - * Source: jdk/internal/misc/VM.lsl:45 - */ public static final int VM_SYSTEM_BOOTED; - /** - * Source: jdk/internal/misc/VM.lsl:44 - */ public static final int VM_SYSTEM_LOADER_INITIALIZING; - /** - * Source: jdk/internal/misc/VM.lsl:46 - */ public static final int VM_SYSTEM_SHUTDOWN; static { @@ -144,18 +72,12 @@ public final class LibSLGlobals { SPLITERATOR_SORTED = 4; SPLITERATOR_SUBSIZED = 16384; SYSTEM_IS_MAC = Engine.makeSymbolicBoolean(); - SYSTEM_IS_WINDOWS = !LibSLGlobals.SYSTEM_IS_MAC && Engine.makeSymbolicBoolean(); + //noinspection ConstantValue + SYSTEM_IS_WINDOWS = !LibSLGlobals.SYSTEM_IS_MAC & Engine.makeSymbolicBoolean(); VM_JAVA_LANG_SYSTEM_INITED = 1; VM_MODULE_SYSTEM_INITED = 2; VM_SYSTEM_BOOTED = 4; VM_SYSTEM_LOADER_INITIALIZING = 3; VM_SYSTEM_SHUTDOWN = 5; } - - @Approximate(LibSLGlobals.class) - public static final class __hook { - private __hook(Void o1, Void o2) { - Engine.assume(false); - } - } } diff --git a/approximations/src/main/java/runtime/LibSLRuntime.java b/approximations/src/main/java/runtime/LibSLRuntime.java index 2f69e534..fb03400d 100644 --- a/approximations/src/main/java/runtime/LibSLRuntime.java +++ b/approximations/src/main/java/runtime/LibSLRuntime.java @@ -10,53 +10,51 @@ import org.usvm.api.SymbolicList; import org.usvm.api.SymbolicMap; -@SuppressWarnings({"unused", "ManualMinMaxCalculation", "ExplicitArrayFilling"}) +@SuppressWarnings("unused") public final class LibSLRuntime { - /* - public static final class Token { - public static final Token INSTANCE = new Token(); - - private Token() {} - } - */ private static final Object SOMETHING = LibSLRuntime.class; - public interface HasAutomaton { - } - @Target(ElementType.CONSTRUCTOR) @Retention(RetentionPolicy.RUNTIME) public @interface DirectCallOnly { } - public interface Automaton { - } + public static abstract class LibSLException extends Error { - @Target(ElementType.CONSTRUCTOR) - @Retention(RetentionPolicy.RUNTIME) - public @interface AutomatonConstructor { - } + @java.io.Serial + private static final long serialVersionUID = 4980196508277280341L; - public static abstract class LibSLException extends Error { private LibSLException(final String msg) { super(msg); } } public static final class StateCheckException extends LibSLException { + + @java.io.Serial + private static final long serialVersionUID = 4980196508277280343L; + private StateCheckException(final String msg) { super(msg); } } public static final class SemanticViolationException extends LibSLException { + + @java.io.Serial + private static final long serialVersionUID = 4980196508277280344L; + private SemanticViolationException(final String msg) { super(msg); } } public static final class IncompleteSpecificationException extends LibSLException { + + @java.io.Serial + private static final long serialVersionUID = 4980196508277280345L; + private IncompleteSpecificationException(final String msg) { // #question: can we pass class and method names here? (counterargument: string bloat) super(msg); @@ -81,6 +79,7 @@ public static void not_implemented() { private static volatile int guid = 0; private static final Object guidLock = new Object(); + @SuppressWarnings("NonAtomicOperationOnVolatileField") public static int getUniqueId() { // TODO: enable synchronization when parallel execution is allowed //synchronized (guidLock) { @@ -117,15 +116,15 @@ public static String toString(byte v) { int len = 0; int pos = BUFF_SIZE_BYTE; while (v != 0) { - pos -= 1; - len += 1; + pos--; + len++; chars[pos] = (char) ('0' + (v % 10)); v /= 10; } if (isNegative) { - pos -= 1; - len += 1; + pos--; + len++; chars[pos] = '-'; } @@ -151,15 +150,15 @@ public static String toString(short v) { int len = 0; int pos = BUFF_SIZE_SHORT; while (v != 0) { - pos -= 1; - len += 1; + pos--; + len++; chars[pos] = (char) ('0' + (v % 10)); v /= 10; } if (isNegative) { - pos -= 1; - len += 1; + pos--; + len++; chars[pos] = '-'; } @@ -185,15 +184,15 @@ public static String toString(int v) { int len = 0; int pos = BUFF_SIZE_INT; while (v != 0) { - pos -= 1; - len += 1; + pos--; + len++; chars[pos] = (char) ('0' + (v % 10)); v /= 10; } if (isNegative) { - pos -= 1; - len += 1; + pos--; + len++; chars[pos] = '-'; } @@ -219,15 +218,15 @@ public static String toString(long v) { int len = 0; int pos = BUFF_SIZE_LONG; while (v != 0) { - pos -= 1; - len += 1; + pos--; + len++; chars[pos] = (char) ('0' + (v % 10)); v /= 10; } if (isNegative) { - pos -= 1; - len += 1; + pos--; + len++; chars[pos] = '-'; } @@ -252,6 +251,7 @@ public static String toString(final char[] v) { private static final int FLOAT_MULTIPLIER_SCIENTIFIC_count = 6; private static final int FLOAT_MULTIPLIER_SCIENTIFIC_int = (int) FLOAT_MULTIPLIER_SCIENTIFIC; + @SuppressWarnings("ManualMinMaxCalculation") public static String toString(float v) { if (v != v) return "NaN"; @@ -283,12 +283,12 @@ public static String toString(float v) { // corrections if (remainder - (float) fraction >= 0.5f) { // rounding of last decimal digit - fraction += 1; + fraction++; // overflow? if (fraction >= FLOAT_MULTIPLIER_REGULAR_int) { fraction = 0; - integral += 1; + integral++; // overflow? if (integral >= 10) @@ -334,7 +334,7 @@ public static String toString(float v) { } if (v >= 1E+1f) { v *= 1E-1f; - exp += 1; + exp++; } } if (v > 0.0f && v <= 1.0f) { @@ -360,7 +360,7 @@ public static String toString(float v) { } if (v < 1E-0f) { v *= 1E1f; - exp -= 1; + exp--; } } @@ -372,17 +372,17 @@ public static String toString(float v) { // corrections if (remainder - (float) fraction >= 0.5f) { // rounding of last decimal digit - fraction += 1; + fraction++; // overflow? if (fraction >= FLOAT_MULTIPLIER_SCIENTIFIC_int) { fraction = 0; - integral += 1; + integral++; // overflow? if (integral >= 10) { integral = 1; - exp += 1; + exp++; } } } @@ -400,6 +400,7 @@ public static String toString(float v) { return (isNegative ? "-" : "").concat(result); } + @SuppressWarnings("ExplicitArrayFilling") private static String prepareFloatFraction(int decimal, final int expectedFractionLength) { if (decimal == 0) return "0"; @@ -408,7 +409,7 @@ private static String prepareFloatFraction(int decimal, final int expectedFracti int cutZeroes = 0; while (decimal % 10 == 0) { decimal /= 10; - cutZeroes += 1; + cutZeroes++; } final String decimals = toString(decimal); @@ -435,6 +436,7 @@ private static String prepareFloatFraction(int decimal, final int expectedFracti private static final int DOUBLE_MULTIPLIER_SCIENTIFIC_count = 15; private static final long DOUBLE_MULTIPLIER_SCIENTIFIC_long = (long) DOUBLE_MULTIPLIER_SCIENTIFIC; + @SuppressWarnings("ManualMinMaxCalculation") public static String toString(double v) { if (v != v) return "NaN"; @@ -466,12 +468,12 @@ public static String toString(double v) { // corrections if (remainder - (double) fraction >= 0.5d) { // rounding of last decimal digit - fraction += 1; + fraction++; // overflow? if (fraction >= DOUBLE_MULTIPLIER_REGULAR_long) { fraction = 0; - integral += 1; + integral++; // overflow? if (integral >= 10) @@ -529,7 +531,7 @@ public static String toString(double v) { } if (v >= 1E+1) { v *= 1E-1; - exp += 1; + exp++; } } if (v > 0.0 && v <= 1.0) { @@ -567,7 +569,7 @@ public static String toString(double v) { } if (v < 1E-0) { v *= 1E1; - exp -= 1; + exp--; } } @@ -579,17 +581,17 @@ public static String toString(double v) { // corrections if (remainder - (double) fraction >= 0.5d) { // rounding of last decimal digit - fraction += 1; + fraction++; // overflow? if (fraction >= DOUBLE_MULTIPLIER_SCIENTIFIC_long) { fraction = 0; - integral += 1; + integral++; // overflow? if (integral >= 10) { integral = 1; - exp += 1; + exp++; } } } @@ -607,6 +609,7 @@ public static String toString(double v) { return (isNegative ? "-" : "").concat(result); } + @SuppressWarnings("ExplicitArrayFilling") private static String prepareDoubleFraction(long decimal, final int expectedFractionLength) { if (decimal == 0) return "0"; @@ -615,7 +618,7 @@ private static String prepareDoubleFraction(long decimal, final int expectedFrac int cutZeroes = 0; while (decimal % 10 == 0) { decimal /= 10; - cutZeroes += 1; + cutZeroes++; } final String decimals = toString(decimal); @@ -726,6 +729,7 @@ public static int hashCode(final int v) { return v; } + @SuppressWarnings("UseHashCodeMethodInspection") public static int hashCode(final long v) { return (int) (v ^ (v >>> 32)); } @@ -744,24 +748,23 @@ public static int hashCode(final double v) { return Double.hashCode(v); } - public static int hashCode(final SymbolicList v) { + public static int hashCode(SymbolicList v, int start, int end) { if (v == null) return 0; - final int count = v.size(); - if (count == 0) - return 1; - Engine.assume(count > 0); - - // FIXME: use less complex approach + Engine.assume(start >= 0); + Engine.assume(end >= 0 && end <= v.size()); int res = 1; - - for (int i = 0; i < count; i++) + for (int i = start; i < end; i++) res = 31 * res + hashCode(v.get(i)); return res; } + public static int hashCode(SymbolicList v) { + return hashCode(v, 0, v.size()); + } + public static int hashCode(final Map v) { if (v == null) return 0; @@ -781,7 +784,7 @@ public static int hashCode(final Map v) { res += hashCode(key) ^ hashCode(unseen.get(key)); unseen.remove(key); - count -= 1; + count--; } return res; @@ -886,7 +889,7 @@ public static boolean equals(final Map a, final Map b) { return false; unseen.remove(key); - length -= 1; + length--; } return true; } @@ -929,6 +932,7 @@ public static final class UnknownAction { // a helper class for complex "array"-related actions public static final class ArrayActions { + @SuppressWarnings({"DataFlowIssue", "SuspiciousSystemArraycopy"}) public static void copy(final Object src, final int srcPos, final Object dst, final int dstPos, final int count) { @@ -941,6 +945,7 @@ public static void copy(final Object src, final int srcPos, System.arraycopy(src, srcPos, dst, dstPos, count); } + @SuppressWarnings({"DataFlowIssue", "ConstantValue"}) public static void fill(final byte[] arr, final byte value) { Engine.assume(arr != null); @@ -951,6 +956,7 @@ public static void fill(final byte[] arr, final byte value) { arr[i] = value; } + @SuppressWarnings({"DataFlowIssue", "ConstantValue"}) public static void fill(final short[] arr, final short value) { Engine.assume(arr != null); @@ -961,6 +967,7 @@ public static void fill(final short[] arr, final short value) { arr[i] = value; } + @SuppressWarnings({"DataFlowIssue", "ConstantValue"}) public static void fill(final int[] arr, final int value) { Engine.assume(arr != null); @@ -971,6 +978,7 @@ public static void fill(final int[] arr, final int value) { arr[i] = value; } + @SuppressWarnings({"DataFlowIssue", "ConstantValue"}) public static void fill(final long[] arr, final long value) { Engine.assume(arr != null); @@ -981,6 +989,7 @@ public static void fill(final long[] arr, final long value) { arr[i] = value; } + @SuppressWarnings({"DataFlowIssue", "ConstantValue"}) public static void fill(final float[] arr, final float value) { Engine.assume(arr != null); @@ -991,6 +1000,7 @@ public static void fill(final float[] arr, final float value) { arr[i] = value; } + @SuppressWarnings({"DataFlowIssue", "ConstantValue"}) public static void fill(final double[] arr, final double value) { Engine.assume(arr != null); @@ -1001,6 +1011,7 @@ public static void fill(final double[] arr, final double value) { arr[i] = value; } + @SuppressWarnings({"DataFlowIssue", "ConstantValue"}) public static void fill(final char[] arr, final char value) { Engine.assume(arr != null); @@ -1011,6 +1022,7 @@ public static void fill(final char[] arr, final char value) { arr[i] = value; } + @SuppressWarnings({"DataFlowIssue", "ConstantValue"}) public static void fill(final T[] arr, final T value) { Engine.assume(arr != null); @@ -1021,6 +1033,7 @@ public static void fill(final T[] arr, final T value) { arr[i] = value; } + @SuppressWarnings({"DataFlowIssue", "ConstantValue"}) public static void fillRange(final byte[] arr, final int fromIndex, final int toIndex, final byte value) { @@ -1037,6 +1050,7 @@ public static void fillRange(final byte[] arr, arr[i] = value; } + @SuppressWarnings({"DataFlowIssue", "ConstantValue"}) public static void fillRange(final short[] arr, final int fromIndex, final int toIndex, final short value) { @@ -1053,6 +1067,7 @@ public static void fillRange(final short[] arr, arr[i] = value; } + @SuppressWarnings({"DataFlowIssue", "ConstantValue"}) public static void fillRange(final int[] arr, final int fromIndex, final int toIndex, final int value) { @@ -1069,6 +1084,7 @@ public static void fillRange(final int[] arr, arr[i] = value; } + @SuppressWarnings({"DataFlowIssue", "ConstantValue"}) public static void fillRange(final long[] arr, final int fromIndex, final int toIndex, final long value) { @@ -1085,6 +1101,7 @@ public static void fillRange(final long[] arr, arr[i] = value; } + @SuppressWarnings({"DataFlowIssue", "ConstantValue"}) public static void fillRange(final float[] arr, final int fromIndex, final int toIndex, final float value) { @@ -1101,6 +1118,7 @@ public static void fillRange(final float[] arr, arr[i] = value; } + @SuppressWarnings({"DataFlowIssue", "ConstantValue"}) public static void fillRange(final double[] arr, final int fromIndex, final int toIndex, final double value) { @@ -1117,6 +1135,7 @@ public static void fillRange(final double[] arr, arr[i] = value; } + @SuppressWarnings({"DataFlowIssue", "ConstantValue"}) public static void fillRange(final char[] arr, final int fromIndex, final int toIndex, final char value) { @@ -1133,6 +1152,7 @@ public static void fillRange(final char[] arr, arr[i] = value; } + @SuppressWarnings({"DataFlowIssue", "ConstantValue"}) public static void fillRange(final T[] arr, final int fromIndex, final int toIndex, final T value) { @@ -1148,20 +1168,21 @@ public static void fillRange(final T[] arr, for (int i = fromIndex; i < toIndex; i++) arr[i] = value; } - } - // a helper class for complex "list"-related actions public static final class ListActions { private static final int INDEX_NOT_FOUND = -1; - public static int find(final SymbolicList list, final Object value, - final int from, final int to) { + private static void addAssumptions(SymbolicList list, int from, int to) { // general assumptions for this function to do something useful Engine.assume(list != null); Engine.assume(0 <= from); Engine.assume(from <= to); + } + + public static int find(SymbolicList list, Object value, int from, int to) { + addAssumptions(list, from, to); // TODO: is there a more efficient solution? if (value == null) { @@ -1169,20 +1190,42 @@ public static int find(final SymbolicList list, final Object value, if (list.get(i) == null) return i; } - } else { - for (int i = from; i < to; i++) { - final Object item = list.get(i); - if (value == item || value.equals(item)) + return INDEX_NOT_FOUND; + } + + for (int i = from; i < to; i++) { + final Object item = list.get(i); + if (value == item || value.equals(item)) + return i; + } + + return INDEX_NOT_FOUND; + } + + public static int findBack(SymbolicList list, Object value, int from, int to) { + addAssumptions(list, from, to); + + // TODO: is there a more efficient solution? + if (value == null) { + for (int i = to - 1; i >= from; i--) { + if (list.get(i) == null) return i; } + return INDEX_NOT_FOUND; + } + + for (int i = to - 1; i >= from; i--) { + final Object item = list.get(i); + if (value == item || value.equals(item)) + return i; } return INDEX_NOT_FOUND; } - } + @SuppressWarnings("DataFlowIssue") public static final class Map { Container map; @@ -1272,7 +1315,7 @@ public void union(final Map other) { map.set(key, unseen.get(key)); unseen.remove(key); - count -= 1; + count--; } } } @@ -1301,7 +1344,7 @@ public void intersection(final Map other) { map.set(key, unseen.get(key)); unseen.remove(key); - count -= 1; + count--; } } } @@ -1340,6 +1383,7 @@ public HashMapContainer() { super(KIND_HASHMAP); } + @SuppressWarnings("DataFlowIssue") @Override public void merge(Map.Container container) { Engine.assume(container instanceof HashMapContainer); @@ -1398,6 +1442,7 @@ public IdentityMapContainer() { super(KIND_IDENTITY_MAP); } + @SuppressWarnings("DataFlowIssue") @Override public void merge(Map.Container container) { Engine.assume(container instanceof IdentityMapContainer); diff --git a/approximations/src/main/java/stub/java/lang/System_PrintStream.java b/approximations/src/main/java/stub/java/lang/System_PrintStream.java index 35d11039..f432a9ea 100644 --- a/approximations/src/main/java/stub/java/lang/System_PrintStream.java +++ b/approximations/src/main/java/stub/java/lang/System_PrintStream.java @@ -1,35 +1,32 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/lang/System.lsl:83 -// package stub.java.lang; +import org.jetbrains.annotations.NotNull; + import java.io.OutputStream; import java.io.PrintStream; import java.lang.CharSequence; import java.lang.LinkageError; import java.lang.Object; import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; import java.util.Locale; -import runtime.LibSLRuntime; -@SuppressWarnings({"all", "unchecked"}) -public final class System_PrintStream extends PrintStream implements LibSLRuntime.HasAutomaton { - private System_PrintStream(Void a, Void b) { +public final class System_PrintStream extends PrintStream { + + @SuppressWarnings({"DataFlowIssue", "unused"}) + public System_PrintStream(boolean closed, boolean error) { super((OutputStream) null); + throw new LinkageError(); } - public PrintStream append(CharSequence csq) { + public System_PrintStream append(CharSequence csq) { throw new LinkageError(); } - public PrintStream append(CharSequence csq, int start, int end) { + public System_PrintStream append(CharSequence csq, int start, int end) { throw new LinkageError(); } - public PrintStream append(char c) { + public System_PrintStream append(char c) { throw new LinkageError(); } @@ -45,11 +42,11 @@ public void flush() { throw new LinkageError(); } - public PrintStream format(Locale l, String format, Object[] args) { + public System_PrintStream format(Locale l, @NotNull String format, Object... args) { throw new LinkageError(); } - public PrintStream format(String format, Object[] args) { + public System_PrintStream format(@NotNull String format, Object... args) { throw new LinkageError(); } @@ -69,7 +66,7 @@ public void print(char c) { throw new LinkageError(); } - public void print(char[] s) { + public void print(@NotNull char[] s) { throw new LinkageError(); } @@ -89,11 +86,11 @@ public void print(long l) { throw new LinkageError(); } - public PrintStream printf(Locale l, String format, Object[] args) { + public System_PrintStream printf(Locale l, @NotNull String format, Object... args) { throw new LinkageError(); } - public PrintStream printf(String format, Object[] args) { + public System_PrintStream printf(@NotNull String format, Object... args) { throw new LinkageError(); } @@ -117,7 +114,7 @@ public void println(char x) { throw new LinkageError(); } - public void println(char[] x) { + public void println(@NotNull char[] x) { throw new LinkageError(); } @@ -141,7 +138,7 @@ public void write(byte[] b) throws java.io.IOException { throw new LinkageError(); } - public void write(byte[] buf, int off, int len) { + public void write(@NotNull byte[] buf, int off, int len) { throw new LinkageError(); } diff --git a/approximations/src/main/java/stub/java/util/AbstractIterator.java b/approximations/src/main/java/stub/java/util/AbstractIterator.java new file mode 100644 index 00000000..785a601e --- /dev/null +++ b/approximations/src/main/java/stub/java/util/AbstractIterator.java @@ -0,0 +1,17 @@ +package stub.java.util; + +import java.util.Iterator; + +public abstract class AbstractIterator implements Iterator { + + @SuppressWarnings("unused") + public AbstractIterator(int expectedModCount) { + throw new LinkageError(); + } + + abstract protected int _parentModCount(); + + protected void _checkForModification() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/AbstractMap_SimpleEntry.java b/approximations/src/main/java/stub/java/util/AbstractMap_SimpleEntry.java deleted file mode 100644 index bc4d0b1d..00000000 --- a/approximations/src/main/java/stub/java/util/AbstractMap_SimpleEntry.java +++ /dev/null @@ -1,53 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/AbstractMap.lsl:23 -// -package stub.java.util; - -import java.io.Serializable; -import java.lang.LinkageError; -import java.lang.Object; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Map; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public class AbstractMap_SimpleEntry implements LibSLRuntime.HasAutomaton, Serializable, Map.Entry { - private AbstractMap_SimpleEntry(Void a, Void b) { - super(); - } - - public AbstractMap_SimpleEntry(Map.Entry entry) { - throw new LinkageError(); - } - - public AbstractMap_SimpleEntry(Object key, Object value) { - throw new LinkageError(); - } - - public boolean equals(Object other) { - throw new LinkageError(); - } - - public Object getKey() { - throw new LinkageError(); - } - - public Object getValue() { - throw new LinkageError(); - } - - public int hashCode() { - throw new LinkageError(); - } - - public Object setValue(Object value) { - throw new LinkageError(); - } - - public String toString() { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/ArrayList_ListItr.java b/approximations/src/main/java/stub/java/util/ArrayList_ListItr.java deleted file mode 100644 index 070b82fd..00000000 --- a/approximations/src/main/java/stub/java/util/ArrayList_ListItr.java +++ /dev/null @@ -1,60 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/ArrayList.lsl:36 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ListIterator; -import java.util.function.Consumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class ArrayList_ListItr implements LibSLRuntime.HasAutomaton, ListIterator { - private ArrayList_ListItr(Void a, Void b) { - super(); - } - - public boolean hasPrevious() { - throw new LinkageError(); - } - - public int nextIndex() { - throw new LinkageError(); - } - - public int previousIndex() { - throw new LinkageError(); - } - - public boolean hasNext() { - throw new LinkageError(); - } - - public Object next() { - throw new LinkageError(); - } - - public Object previous() { - throw new LinkageError(); - } - - public void remove() { - throw new LinkageError(); - } - - public void set(Object e) { - throw new LinkageError(); - } - - public void add(Object e) { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer userAction) { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/ArrayList_Spliterator.java b/approximations/src/main/java/stub/java/util/ArrayList_Spliterator.java deleted file mode 100644 index 186a94a2..00000000 --- a/approximations/src/main/java/stub/java/util/ArrayList_Spliterator.java +++ /dev/null @@ -1,48 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/ArrayList.lsl:45 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ArrayList; -import java.util.Spliterator; -import java.util.function.Consumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class ArrayList_Spliterator implements LibSLRuntime.HasAutomaton, Spliterator { - private ArrayList_Spliterator(Void a, Void b) { - super(); - } - - private ArrayList_Spliterator(ArrayList _this, int origin, int fence, int expectedModCount) { - throw new LinkageError(); - } - - public int characteristics() { - throw new LinkageError(); - } - - public long estimateSize() { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer _action) { - throw new LinkageError(); - } - - public long getExactSizeIfKnown() { - throw new LinkageError(); - } - - public boolean tryAdvance(Consumer _action) { - throw new LinkageError(); - } - - public Spliterator trySplit() { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/ArrayList_SubList$ListIterator.java b/approximations/src/main/java/stub/java/util/ArrayList_SubList$ListIterator.java deleted file mode 100644 index ee24c0e1..00000000 --- a/approximations/src/main/java/stub/java/util/ArrayList_SubList$ListIterator.java +++ /dev/null @@ -1,60 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/ArrayList.lsl:75 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ListIterator; -import java.util.function.Consumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class ArrayList_SubList$ListIterator implements LibSLRuntime.HasAutomaton, ListIterator { - private ArrayList_SubList$ListIterator(Void a, Void b) { - super(); - } - - public boolean hasPrevious() { - throw new LinkageError(); - } - - public int nextIndex() { - throw new LinkageError(); - } - - public int previousIndex() { - throw new LinkageError(); - } - - public boolean hasNext() { - throw new LinkageError(); - } - - public Object next() { - throw new LinkageError(); - } - - public Object previous() { - throw new LinkageError(); - } - - public void remove() { - throw new LinkageError(); - } - - public void set(Object e) { - throw new LinkageError(); - } - - public void add(Object e) { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer userAction) { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/ArrayList_SubList$Spliterator.java b/approximations/src/main/java/stub/java/util/ArrayList_SubList$Spliterator.java deleted file mode 100644 index e64e7a39..00000000 --- a/approximations/src/main/java/stub/java/util/ArrayList_SubList$Spliterator.java +++ /dev/null @@ -1,43 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/ArrayList.lsl:65 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Spliterator; -import java.util.function.Consumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class ArrayList_SubList$Spliterator implements LibSLRuntime.HasAutomaton, Spliterator { - private ArrayList_SubList$Spliterator(Void a, Void b) { - super(); - } - - public int characteristics() { - throw new LinkageError(); - } - - public long estimateSize() { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer _action) { - throw new LinkageError(); - } - - public long getExactSizeIfKnown() { - throw new LinkageError(); - } - - public boolean tryAdvance(Consumer _action) { - throw new LinkageError(); - } - - public Spliterator trySplit() { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/ArrayList_SubList.java b/approximations/src/main/java/stub/java/util/ArrayList_SubList.java deleted file mode 100644 index dc8c7db0..00000000 --- a/approximations/src/main/java/stub/java/util/ArrayList_SubList.java +++ /dev/null @@ -1,177 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/ArrayList.lsl:54 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.Object; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.AbstractList; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.RandomAccess; -import java.util.Spliterator; -import java.util.function.Consumer; -import java.util.function.IntFunction; -import java.util.function.Predicate; -import java.util.function.UnaryOperator; -import java.util.stream.Stream; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class ArrayList_SubList extends AbstractList implements LibSLRuntime.HasAutomaton, List, RandomAccess { - private ArrayList_SubList(Void a, Void b) { - super(); - } - - public ArrayList_SubList(ArrayList root, int fromIndex, int toIndex) { - throw new LinkageError(); - } - - private ArrayList_SubList(ArrayList_SubList parent, int fromIndex, int toIndex) { - throw new LinkageError(); - } - - public boolean add(Object e) { - throw new LinkageError(); - } - - public void add(int index, Object element) { - throw new LinkageError(); - } - - public boolean addAll(Collection c) { - throw new LinkageError(); - } - - public boolean addAll(int index, Collection c) { - throw new LinkageError(); - } - - public void clear() { - throw new LinkageError(); - } - - public boolean contains(Object o) { - throw new LinkageError(); - } - - public boolean containsAll(Collection c) { - throw new LinkageError(); - } - - public boolean equals(Object o) { - throw new LinkageError(); - } - - public void forEach(Consumer _action) { - throw new LinkageError(); - } - - public Object get(int index) { - throw new LinkageError(); - } - - public int hashCode() { - throw new LinkageError(); - } - - public int indexOf(Object o) { - throw new LinkageError(); - } - - public boolean isEmpty() { - throw new LinkageError(); - } - - public Iterator iterator() { - throw new LinkageError(); - } - - public int lastIndexOf(Object o) { - throw new LinkageError(); - } - - public ListIterator listIterator() { - throw new LinkageError(); - } - - public ListIterator listIterator(int index) { - throw new LinkageError(); - } - - public Stream parallelStream() { - throw new LinkageError(); - } - - public boolean remove(Object o) { - throw new LinkageError(); - } - - public Object remove(int index) { - throw new LinkageError(); - } - - public boolean removeAll(Collection c) { - throw new LinkageError(); - } - - public boolean removeIf(Predicate filter) { - throw new LinkageError(); - } - - public void replaceAll(UnaryOperator operator) { - throw new LinkageError(); - } - - public boolean retainAll(Collection c) { - throw new LinkageError(); - } - - public Object set(int index, Object element) { - throw new LinkageError(); - } - - public int size() { - throw new LinkageError(); - } - - public void sort(Comparator c) { - throw new LinkageError(); - } - - public Spliterator spliterator() { - throw new LinkageError(); - } - - public Stream stream() { - throw new LinkageError(); - } - - public List subList(int fromIndex, int toIndex) { - throw new LinkageError(); - } - - public Object[] toArray() { - throw new LinkageError(); - } - - public Object[] toArray(IntFunction generator) { - throw new LinkageError(); - } - - public Object[] toArray(Object[] a) { - throw new LinkageError(); - } - - public String toString() { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/ByteBufferAsCharBufferB.java b/approximations/src/main/java/stub/java/util/ByteBufferAsCharBufferB.java new file mode 100644 index 00000000..e14c9540 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/ByteBufferAsCharBufferB.java @@ -0,0 +1,4 @@ +package stub.java.util; + +public class ByteBufferAsCharBufferB { +} diff --git a/approximations/src/main/java/stub/java/util/ByteBufferAsCharBufferRB.java b/approximations/src/main/java/stub/java/util/ByteBufferAsCharBufferRB.java new file mode 100644 index 00000000..ada2ecc3 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/ByteBufferAsCharBufferRB.java @@ -0,0 +1,4 @@ +package stub.java.util; + +public class ByteBufferAsCharBufferRB { +} diff --git a/approximations/src/main/java/stub/java/util/DirectByteBuffer.java b/approximations/src/main/java/stub/java/util/DirectByteBuffer.java new file mode 100644 index 00000000..4178806d --- /dev/null +++ b/approximations/src/main/java/stub/java/util/DirectByteBuffer.java @@ -0,0 +1,227 @@ +package stub.java.util; + +import jdk.internal.ref.Cleaner; +import sun.nio.ch.DirectBuffer; + +import java.io.FileDescriptor; +import java.nio.*; + +public class DirectByteBuffer { + DirectByteBuffer(int cap) { + throw new LinkageError(); + } + + DirectByteBuffer(int cap, Object ob, byte[] segment) { + throw new LinkageError(); + } + + DirectByteBuffer(int cap, Object ob, FileDescriptor fd, boolean isSync, byte[] segment) { + throw new LinkageError(); + } + + protected DirectByteBuffer(int cap, FileDescriptor fd, boolean isSync, byte[] segment) { + throw new LinkageError(); + } + + DirectByteBuffer(DirectBuffer db, int mark, int pos, int lim, int cap, int off, byte[] segment) { + throw new LinkageError(); + } + + Object base() { + throw new LinkageError(); + } + + public ByteBuffer slice() { + throw new LinkageError(); + } + + public ByteBuffer slice(int index, int length) { + throw new LinkageError(); + } + + public ByteBuffer duplicate() { + throw new LinkageError(); + } + + public ByteBuffer asReadOnlyBuffer() { + throw new LinkageError(); + } + + public long address() { + throw new LinkageError(); + } + + public Object attachment() { + throw new LinkageError(); + } + + public Cleaner cleaner() { + throw new LinkageError(); + } + + public byte get() { + throw new LinkageError(); + } + + public byte get(int i) { + throw new LinkageError(); + } + + public ByteBuffer get(int index, byte[] dst, int offset, int length) { + throw new LinkageError(); + } + + public ByteBuffer put(byte x) { + throw new LinkageError(); + } + + public ByteBuffer put(int i, byte x) { + throw new LinkageError(); + } + + public ByteBuffer put(ByteBuffer src) { + throw new LinkageError(); + } + + public ByteBuffer put(int index, ByteBuffer src, int offset, int length) { + throw new LinkageError(); + } + + public ByteBuffer put(byte[] src, int offset, int length) { + throw new LinkageError(); + } + + public ByteBuffer put(int index, byte[] src, int offset, int length) { + throw new LinkageError(); + } + + public ByteBuffer compact() { + throw new LinkageError(); + } + + public boolean isDirect() { + throw new LinkageError(); + } + + public boolean isReadOnly() { + throw new LinkageError(); + } + + public char getChar() { + throw new LinkageError(); + } + + public char getChar(int i) { + throw new LinkageError(); + } + + public ByteBuffer putChar(char x) { throw new LinkageError(); } + + public ByteBuffer putChar(int i, char x) { + throw new LinkageError(); + } + + public CharBuffer asCharBuffer() { + throw new LinkageError(); + } + + public short getShort() { + throw new LinkageError(); + } + + public short getShort(int i) { + throw new LinkageError(); + } + + public ByteBuffer putShort(short x) { + throw new LinkageError(); + } + + public ByteBuffer putShort(int i, short x) { + throw new LinkageError(); + } + + public ShortBuffer asShortBuffer() { + throw new LinkageError(); + } + + public int getInt() { + throw new LinkageError(); + } + + public int getInt(int i) { + throw new LinkageError(); + } + + public ByteBuffer putInt(int x) { + throw new LinkageError(); + } + + public ByteBuffer putInt(int i, int x) { + throw new LinkageError(); + } + + public IntBuffer asIntBuffer() { + throw new LinkageError(); + } + + public long getLong() { + throw new LinkageError(); + } + + public long getLong(int i) { + throw new LinkageError(); + } + + public ByteBuffer putLong(long x) { + throw new LinkageError(); + } + + public ByteBuffer putLong(int i, long x) { + throw new LinkageError(); + } + + public LongBuffer asLongBuffer() { + throw new LinkageError(); + } + + public float getFloat() { + throw new LinkageError(); + } + + public float getFloat(int i) { + throw new LinkageError(); + } + + public ByteBuffer putFloat(float x) { + throw new LinkageError(); + } + + public ByteBuffer putFloat(int i, float x) { + throw new LinkageError(); + } + + public FloatBuffer asFloatBuffer() { + throw new LinkageError(); + } + + public double getDouble() { + throw new LinkageError(); + } + + public double getDouble(int i) { + throw new LinkageError(); + } + + public ByteBuffer putDouble(double x) { + throw new LinkageError(); + } + + public ByteBuffer putDouble(int i, double x) { + throw new LinkageError(); + } + + public DoubleBuffer asDoubleBuffer() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/DirectByteBufferR.java b/approximations/src/main/java/stub/java/util/DirectByteBufferR.java new file mode 100644 index 00000000..a1733b69 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/DirectByteBufferR.java @@ -0,0 +1,164 @@ +package stub.java.util; + +import sun.nio.ch.DirectBuffer; + +import java.io.FileDescriptor; +import java.nio.*; + +public class DirectByteBufferR { + DirectByteBufferR(int cap) { + throw new LinkageError(); + } + + protected DirectByteBufferR(int cap, FileDescriptor fd, boolean isSync, byte[] segment) { + throw new LinkageError(); + } + + DirectByteBufferR(DirectBuffer db, int mark, int pos, int lim, int cap, int off, byte[] segment) { + throw new LinkageError(); + } + + public ByteBuffer slice() { + throw new LinkageError(); + } + + public ByteBuffer slice(int index, int length) { + throw new LinkageError(); + } + + public ByteBuffer duplicate() { + throw new LinkageError(); + } + + public ByteBuffer asReadOnlyBuffer() { + throw new LinkageError(); + } + + public ByteBuffer put(byte x) { + throw new LinkageError(); + } + + public ByteBuffer put(int i, byte x) { + throw new LinkageError(); + } + + public ByteBuffer put(ByteBuffer src) { + throw new LinkageError(); + } + + public ByteBuffer put(int index, ByteBuffer src, int offset, int length) { + throw new LinkageError(); + } + + public ByteBuffer put(byte[] src, int offset, int length) { + throw new LinkageError(); + } + + public ByteBuffer put(int index, byte[] src, int offset, int length) { + throw new LinkageError(); + } + + public ByteBuffer compact() { + throw new LinkageError(); + } + + public boolean isReadOnly() { + throw new LinkageError(); + } + + private ByteBuffer putChar(long a, char x) { + throw new LinkageError(); + } + + public ByteBuffer putChar(char x) { + throw new LinkageError(); + } + + public ByteBuffer putChar(int i, char x) { + throw new LinkageError(); + } + + public CharBuffer asCharBuffer() { + throw new LinkageError(); + } + + private ByteBuffer putShort(long a, short x) { + throw new LinkageError(); + } + + public ByteBuffer putShort(short x) { + throw new LinkageError(); + } + + public ByteBuffer putShort(int i, short x) { + throw new LinkageError(); + } + + public ShortBuffer asShortBuffer() { + throw new LinkageError(); + } + + private ByteBuffer putInt(long a, int x) { + throw new LinkageError(); + } + + public ByteBuffer putInt(int x) { + throw new LinkageError(); + } + + public ByteBuffer putInt(int i, int x) { + throw new LinkageError(); + } + + public IntBuffer asIntBuffer() { + throw new LinkageError(); + } + + private ByteBuffer putLong(long a, long x) { + throw new LinkageError(); + } + + public ByteBuffer putLong(long x) { + throw new LinkageError(); + } + + public ByteBuffer putLong(int i, long x) { + throw new LinkageError(); + } + + public LongBuffer asLongBuffer() { + throw new LinkageError(); + } + + private ByteBuffer putFloat(long a, float x) { + throw new LinkageError(); + } + + public ByteBuffer putFloat(float x) { + throw new LinkageError(); + } + + public ByteBuffer putFloat(int i, float x) { + throw new LinkageError(); + } + + public FloatBuffer asFloatBuffer() { + throw new LinkageError(); + } + + private ByteBuffer putDouble(long a, double x) { + throw new LinkageError(); + } + + public ByteBuffer putDouble(double x) { + throw new LinkageError(); + } + + public ByteBuffer putDouble(int i, double x) { + throw new LinkageError(); + } + + public DoubleBuffer asDoubleBuffer() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/DirectCharBufferRU.java b/approximations/src/main/java/stub/java/util/DirectCharBufferRU.java new file mode 100644 index 00000000..b74b5602 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/DirectCharBufferRU.java @@ -0,0 +1,67 @@ +package stub.java.util; + +import sun.nio.ch.DirectBuffer; + +import java.nio.CharBuffer; + +public class DirectCharBufferRU { + DirectCharBufferRU(DirectBuffer db, int mark, int pos, int lim, int cap, int off, char[] segment) { + throw new LinkageError(); + } + + public CharBuffer slice() { + throw new LinkageError(); + } + + public CharBuffer slice(int index, int length) { + throw new LinkageError(); + } + + public CharBuffer duplicate() { + throw new LinkageError(); + } + + public CharBuffer asReadOnlyBuffer() { + throw new LinkageError(); + } + + public CharBuffer put(char x) { + throw new LinkageError(); + } + + public CharBuffer put(int i, char x) { + throw new LinkageError(); + } + + public CharBuffer put(CharBuffer src) { + throw new LinkageError(); + } + + public CharBuffer put(int index, CharBuffer src, int offset, int length) { + throw new LinkageError(); + } + + public CharBuffer put(char[] src, int offset, int length) { + throw new LinkageError(); + } + + public CharBuffer put(int index, char[] src, int offset, int length) { + throw new LinkageError(); + } + + public CharBuffer compact() { + throw new LinkageError(); + } + + public boolean isReadOnly() { + throw new LinkageError(); + } + + public String toString(int start, int end) { + throw new LinkageError(); + } + + public CharBuffer subSequence(int start, int end) { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/DirectCharBufferU.java b/approximations/src/main/java/stub/java/util/DirectCharBufferU.java new file mode 100644 index 00000000..5ded4dd8 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/DirectCharBufferU.java @@ -0,0 +1,115 @@ +package stub.java.util; + +import jdk.internal.ref.Cleaner; +import sun.nio.ch.DirectBuffer; + +import java.nio.ByteOrder; +import java.nio.CharBuffer; + +public class DirectCharBufferU { + DirectCharBufferU(DirectBuffer db, int mark, int pos, int lim, int cap, int off, char[] segment) { + throw new LinkageError(); + } + + public Object attachment() { + throw new LinkageError(); + } + + public Cleaner cleaner() { throw new LinkageError(); } + + Object base() { + throw new LinkageError(); + } + + public CharBuffer slice() { + throw new LinkageError(); + } + + public CharBuffer slice(int index, int length) { + throw new LinkageError(); + } + + public CharBuffer duplicate() { + throw new LinkageError(); + } + + public CharBuffer asReadOnlyBuffer() { + throw new LinkageError(); + } + + public long address() { + throw new LinkageError(); + } + + public char get() { + throw new LinkageError(); + } + + public char get(int i) { + throw new LinkageError(); + } + + char getUnchecked(int i) { + throw new LinkageError(); + } + + public CharBuffer get(char[] dst, int offset, int length) { + throw new LinkageError(); + } + + public CharBuffer get(int index, char[] dst, int offset, int length) { + throw new LinkageError(); + } + + public CharBuffer put(char x) { + throw new LinkageError(); + } + + public CharBuffer put(int i, char x) { + throw new LinkageError(); + } + + public CharBuffer put(CharBuffer src) { + throw new LinkageError(); + } + + public CharBuffer put(int index, CharBuffer src, int offset, int length) { + throw new LinkageError(); + } + + public CharBuffer put(char[] src, int offset, int length) { + throw new LinkageError(); + } + + public CharBuffer put(int index, char[] src, int offset, int length) { + throw new LinkageError(); + } + + public CharBuffer compact() { + throw new LinkageError(); + } + + public boolean isDirect() { + throw new LinkageError(); + } + + public boolean isReadOnly() { + throw new LinkageError(); + } + + public String toString(int start, int end) { + throw new LinkageError(); + } + + public CharBuffer subSequence(int start, int end) { + throw new LinkageError(); + } + + public ByteOrder order() { + throw new LinkageError(); + } + + ByteOrder charRegionOrder() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/DirectFloatBufferU.java b/approximations/src/main/java/stub/java/util/DirectFloatBufferU.java new file mode 100644 index 00000000..57b3f491 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/DirectFloatBufferU.java @@ -0,0 +1,99 @@ +package stub.java.util; + +import jdk.internal.ref.Cleaner; +import sun.nio.ch.DirectBuffer; + +import java.nio.ByteOrder; +import java.nio.FloatBuffer; + +public class DirectFloatBufferU { + public Object attachment() { + throw new LinkageError(); + } + + public Cleaner cleaner() { throw new LinkageError(); } + + DirectFloatBufferU(DirectBuffer db, int mark, int pos, int lim, int cap, int off, float[] segment) { + throw new LinkageError(); + } + + Object base() { + throw new LinkageError(); + } + + public FloatBuffer slice() { + throw new LinkageError(); + } + + public FloatBuffer slice(int index, int length) { + throw new LinkageError(); + } + + public FloatBuffer duplicate() { + throw new LinkageError(); + } + + public FloatBuffer asReadOnlyBuffer() { + throw new LinkageError(); + } + + public long address() { + throw new LinkageError(); + } + + public float get() { + throw new LinkageError(); + } + + public float get(int i) { + throw new LinkageError(); + } + + public FloatBuffer get(float[] dst, int offset, int length) { + throw new LinkageError(); + } + + public FloatBuffer get(int index, float[] dst, int offset, int length) { + throw new LinkageError(); + } + + public FloatBuffer put(float x) { + throw new LinkageError(); + } + + public FloatBuffer put(int i, float x) { + throw new LinkageError(); + } + + public FloatBuffer put(FloatBuffer src) { + throw new LinkageError(); + } + + public FloatBuffer put(int index, FloatBuffer src, int offset, int length) { + throw new LinkageError(); + } + + public FloatBuffer put(float[] src, int offset, int length) { + throw new LinkageError(); + } + + public FloatBuffer put(int index, float[] src, int offset, int length) { + throw new LinkageError(); + } + + public FloatBuffer compact() { + throw new LinkageError(); + } + + public boolean isDirect() { + throw new LinkageError(); + } + + public boolean isReadOnly() { + throw new LinkageError(); + } + + public ByteOrder order() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/DirectIntBufferRU.java b/approximations/src/main/java/stub/java/util/DirectIntBufferRU.java new file mode 100644 index 00000000..c5f11d9e --- /dev/null +++ b/approximations/src/main/java/stub/java/util/DirectIntBufferRU.java @@ -0,0 +1,72 @@ +package stub.java.util; + +import sun.nio.ch.DirectBuffer; + +import java.nio.ByteOrder; +import java.nio.IntBuffer; + +public class DirectIntBufferRU { + DirectIntBufferRU(DirectBuffer db, int mark, int pos, int lim, int cap, int off, int[] segment) { + throw new LinkageError(); + } + + Object base() { + throw new LinkageError(); + } + + public IntBuffer slice() { + throw new LinkageError(); + } + + public IntBuffer slice(int index, int length) { + throw new LinkageError(); + } + + public IntBuffer duplicate() { + throw new LinkageError(); + } + + public IntBuffer asReadOnlyBuffer() { + throw new LinkageError(); + } + + public IntBuffer put(int x) { + throw new LinkageError(); + } + + public IntBuffer put(int i, int x) { + throw new LinkageError(); + } + + public IntBuffer put(IntBuffer src) { + throw new LinkageError(); + } + + public IntBuffer put(int index, IntBuffer src, int offset, int length) { + throw new LinkageError(); + } + + public IntBuffer put(int[] src, int offset, int length) { + throw new LinkageError(); + } + + public IntBuffer put(int index, int[] src, int offset, int length) { + throw new LinkageError(); + } + + public IntBuffer compact() { + throw new LinkageError(); + } + + public boolean isDirect() { + throw new LinkageError(); + } + + public boolean isReadOnly() { + throw new LinkageError(); + } + + public ByteOrder order() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/DirectIntBufferU.java b/approximations/src/main/java/stub/java/util/DirectIntBufferU.java new file mode 100644 index 00000000..9e5d70a6 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/DirectIntBufferU.java @@ -0,0 +1,99 @@ +package stub.java.util; + +import jdk.internal.ref.Cleaner; +import sun.nio.ch.DirectBuffer; + +import java.nio.ByteOrder; +import java.nio.IntBuffer; + +public class DirectIntBufferU { + DirectIntBufferU(DirectBuffer db, int mark, int pos, int lim, int cap, int off, int[] segment) { + throw new LinkageError(); + } + + public Object attachment() { + throw new LinkageError(); + } + + public Cleaner cleaner() { throw new LinkageError(); } + + Object base() { + throw new LinkageError(); + } + + public IntBuffer slice() { + throw new LinkageError(); + } + + public IntBuffer slice(int index, int length) { + throw new LinkageError(); + } + + public IntBuffer duplicate() { + throw new LinkageError(); + } + + public IntBuffer asReadOnlyBuffer() { + throw new LinkageError(); + } + + public long address() { + throw new LinkageError(); + } + + public int get() { + throw new LinkageError(); + } + + public int get(int i) { + throw new LinkageError(); + } + + public IntBuffer get(int[] dst, int offset, int length) { + throw new LinkageError(); + } + + public IntBuffer get(int index, int[] dst, int offset, int length) { + throw new LinkageError(); + } + + public IntBuffer put(int x) { + throw new LinkageError(); + } + + public IntBuffer put(int i, int x) { + throw new LinkageError(); + } + + public IntBuffer put(IntBuffer src) { + throw new LinkageError(); + } + + public IntBuffer put(int index, IntBuffer src, int offset, int length) { + throw new LinkageError(); + } + + public IntBuffer put(int[] src, int offset, int length) { + throw new LinkageError(); + } + + public IntBuffer put(int index, int[] src, int offset, int length) { + throw new LinkageError(); + } + + public IntBuffer compact() { + throw new LinkageError(); + } + + public boolean isDirect() { + throw new LinkageError(); + } + + public boolean isReadOnly() { + throw new LinkageError(); + } + + public ByteOrder order() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/HashMap_EntryIterator.java b/approximations/src/main/java/stub/java/util/HashMap_EntryIterator.java deleted file mode 100644 index d8b96c6c..00000000 --- a/approximations/src/main/java/stub/java/util/HashMap_EntryIterator.java +++ /dev/null @@ -1,36 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashMap.lsl:99 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Iterator; -import java.util.Map; -import java.util.function.Consumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class HashMap_EntryIterator implements LibSLRuntime.HasAutomaton, Iterator { - private HashMap_EntryIterator(Void a, Void b) { - super(); - } - - public void forEachRemaining(Consumer userAction) { - throw new LinkageError(); - } - - public final boolean hasNext() { - throw new LinkageError(); - } - - public final Map.Entry next() { - throw new LinkageError(); - } - - public final void remove() { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/HashMap_EntrySet.java b/approximations/src/main/java/stub/java/util/HashMap_EntrySet.java deleted file mode 100644 index b76074f4..00000000 --- a/approximations/src/main/java/stub/java/util/HashMap_EntrySet.java +++ /dev/null @@ -1,115 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashMap.lsl:90 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.Object; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.AbstractSet; -import java.util.Collection; -import java.util.Iterator; -import java.util.Spliterator; -import java.util.function.Consumer; -import java.util.function.IntFunction; -import java.util.function.Predicate; -import java.util.stream.Stream; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class HashMap_EntrySet extends AbstractSet implements LibSLRuntime.HasAutomaton { - private HashMap_EntrySet(Void a, Void b) { - super(); - } - - public boolean add(Object e) { - throw new LinkageError(); - } - - public boolean addAll(Collection c) { - throw new LinkageError(); - } - - public final void clear() { - throw new LinkageError(); - } - - public final boolean contains(Object o) { - throw new LinkageError(); - } - - public boolean containsAll(Collection c) { - throw new LinkageError(); - } - - public boolean equals(Object other) { - throw new LinkageError(); - } - - public final void forEach(Consumer userAction) { - throw new LinkageError(); - } - - public int hashCode() { - throw new LinkageError(); - } - - public boolean isEmpty() { - throw new LinkageError(); - } - - public final Iterator iterator() { - throw new LinkageError(); - } - - public Stream parallelStream() { - throw new LinkageError(); - } - - public final boolean remove(Object o) { - throw new LinkageError(); - } - - public boolean removeAll(Collection c) { - throw new LinkageError(); - } - - public boolean removeIf(Predicate filter) { - throw new LinkageError(); - } - - public boolean retainAll(Collection c) { - throw new LinkageError(); - } - - public final int size() { - throw new LinkageError(); - } - - public final Spliterator spliterator() { - throw new LinkageError(); - } - - public Stream stream() { - throw new LinkageError(); - } - - public Object[] toArray() { - throw new LinkageError(); - } - - public Object[] toArray(IntFunction generator) { - throw new LinkageError(); - } - - public Object[] toArray(Object[] a) { - throw new LinkageError(); - } - - public String toString() { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/HashMap_EntrySpliterator.java b/approximations/src/main/java/stub/java/util/HashMap_EntrySpliterator.java deleted file mode 100644 index 39eea530..00000000 --- a/approximations/src/main/java/stub/java/util/HashMap_EntrySpliterator.java +++ /dev/null @@ -1,43 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashMap.lsl:108 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Spliterator; -import java.util.function.Consumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class HashMap_EntrySpliterator implements LibSLRuntime.HasAutomaton, Spliterator { - private HashMap_EntrySpliterator(Void a, Void b) { - super(); - } - - public int characteristics() { - throw new LinkageError(); - } - - public final long estimateSize() { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer userAction) { - throw new LinkageError(); - } - - public long getExactSizeIfKnown() { - throw new LinkageError(); - } - - public boolean tryAdvance(Consumer userAction) { - throw new LinkageError(); - } - - public Spliterator trySplit() { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/HashMap_KeyIterator.java b/approximations/src/main/java/stub/java/util/HashMap_KeyIterator.java deleted file mode 100644 index 96a73a06..00000000 --- a/approximations/src/main/java/stub/java/util/HashMap_KeyIterator.java +++ /dev/null @@ -1,36 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashMap.lsl:72 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Iterator; -import java.util.function.Consumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class HashMap_KeyIterator implements LibSLRuntime.HasAutomaton, Iterator { - private HashMap_KeyIterator(Void a, Void b) { - super(); - } - - public void forEachRemaining(Consumer userAction) { - throw new LinkageError(); - } - - public final boolean hasNext() { - throw new LinkageError(); - } - - public final Object next() { - throw new LinkageError(); - } - - public final void remove() { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/HashMap_KeySpliterator.java b/approximations/src/main/java/stub/java/util/HashMap_KeySpliterator.java deleted file mode 100644 index f1109b43..00000000 --- a/approximations/src/main/java/stub/java/util/HashMap_KeySpliterator.java +++ /dev/null @@ -1,43 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashMap.lsl:81 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Spliterator; -import java.util.function.Consumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class HashMap_KeySpliterator implements LibSLRuntime.HasAutomaton, Spliterator { - private HashMap_KeySpliterator(Void a, Void b) { - super(); - } - - public int characteristics() { - throw new LinkageError(); - } - - public final long estimateSize() { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer userAction) { - throw new LinkageError(); - } - - public long getExactSizeIfKnown() { - throw new LinkageError(); - } - - public boolean tryAdvance(Consumer userAction) { - throw new LinkageError(); - } - - public Spliterator trySplit() { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/HashMap_ValueIterator.java b/approximations/src/main/java/stub/java/util/HashMap_ValueIterator.java deleted file mode 100644 index 3ebaa49f..00000000 --- a/approximations/src/main/java/stub/java/util/HashMap_ValueIterator.java +++ /dev/null @@ -1,36 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashMap.lsl:45 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Iterator; -import java.util.function.Consumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public class HashMap_ValueIterator implements LibSLRuntime.HasAutomaton, Iterator { - private HashMap_ValueIterator(Void a, Void b) { - super(); - } - - public void forEachRemaining(Consumer userAction) { - throw new LinkageError(); - } - - public final boolean hasNext() { - throw new LinkageError(); - } - - public final Object next() { - throw new LinkageError(); - } - - public final void remove() { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/HashMap_ValueSpliterator.java b/approximations/src/main/java/stub/java/util/HashMap_ValueSpliterator.java deleted file mode 100644 index d89797c1..00000000 --- a/approximations/src/main/java/stub/java/util/HashMap_ValueSpliterator.java +++ /dev/null @@ -1,43 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashMap.lsl:54 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Spliterator; -import java.util.function.Consumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class HashMap_ValueSpliterator implements LibSLRuntime.HasAutomaton, Spliterator { - private HashMap_ValueSpliterator(Void a, Void b) { - super(); - } - - public int characteristics() { - throw new LinkageError(); - } - - public final long estimateSize() { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer userAction) { - throw new LinkageError(); - } - - public long getExactSizeIfKnown() { - throw new LinkageError(); - } - - public boolean tryAdvance(Consumer userAction) { - throw new LinkageError(); - } - - public Spliterator trySplit() { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/HashMap_Values.java b/approximations/src/main/java/stub/java/util/HashMap_Values.java deleted file mode 100644 index 24ef048d..00000000 --- a/approximations/src/main/java/stub/java/util/HashMap_Values.java +++ /dev/null @@ -1,107 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashMap.lsl:36 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.Object; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.AbstractCollection; -import java.util.Collection; -import java.util.Iterator; -import java.util.Spliterator; -import java.util.function.Consumer; -import java.util.function.IntFunction; -import java.util.function.Predicate; -import java.util.stream.Stream; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public class HashMap_Values extends AbstractCollection implements LibSLRuntime.HasAutomaton { - private HashMap_Values(Void a, Void b) { - super(); - } - - public boolean add(Object e) { - throw new LinkageError(); - } - - public boolean addAll(Collection c) { - throw new LinkageError(); - } - - public final void clear() { - throw new LinkageError(); - } - - public final boolean contains(Object value) { - throw new LinkageError(); - } - - public boolean containsAll(Collection c) { - throw new LinkageError(); - } - - public final void forEach(Consumer userAction) { - throw new LinkageError(); - } - - public boolean isEmpty() { - throw new LinkageError(); - } - - public final Iterator iterator() { - throw new LinkageError(); - } - - public Stream parallelStream() { - throw new LinkageError(); - } - - public boolean remove(Object value) { - throw new LinkageError(); - } - - public boolean removeAll(Collection c) { - throw new LinkageError(); - } - - public boolean removeIf(Predicate filter) { - throw new LinkageError(); - } - - public boolean retainAll(Collection c) { - throw new LinkageError(); - } - - public final int size() { - throw new LinkageError(); - } - - public final Spliterator spliterator() { - throw new LinkageError(); - } - - public Stream stream() { - throw new LinkageError(); - } - - public Object[] toArray() { - throw new LinkageError(); - } - - public Object[] toArray(IntFunction generator) { - throw new LinkageError(); - } - - public Object[] toArray(Object[] a) { - throw new LinkageError(); - } - - public String toString() { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/HashSet_KeyIterator.java b/approximations/src/main/java/stub/java/util/HashSet_KeyIterator.java deleted file mode 100644 index e3c17984..00000000 --- a/approximations/src/main/java/stub/java/util/HashSet_KeyIterator.java +++ /dev/null @@ -1,41 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashSet.lsl:41 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.HashMap; -import java.util.Iterator; -import java.util.function.Consumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class HashSet_KeyIterator implements LibSLRuntime.HasAutomaton, Iterator { - private HashSet_KeyIterator(Void a, Void b) { - super(); - } - - private HashSet_KeyIterator(HashMap source) { - throw new LinkageError(); - } - - public boolean hasNext() { - throw new LinkageError(); - } - - public final Object next() { - throw new LinkageError(); - } - - public void remove() { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer userAction) { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/HashSet_KeySpliterator.java b/approximations/src/main/java/stub/java/util/HashSet_KeySpliterator.java deleted file mode 100644 index 609d2b94..00000000 --- a/approximations/src/main/java/stub/java/util/HashSet_KeySpliterator.java +++ /dev/null @@ -1,45 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashSet.lsl:32 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.HashMap; -import java.util.Spliterator; -import java.util.function.Consumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class HashSet_KeySpliterator implements LibSLRuntime.HasAutomaton, Spliterator { - private HashSet_KeySpliterator(Void a, Void b) { - super(); - } - - private HashSet_KeySpliterator(HashMap source, int origin, int fence, int est, - int expectedModCount) { - throw new LinkageError(); - } - - public long estimateSize() { - throw new LinkageError(); - } - - public int characteristics() { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer userAction) { - throw new LinkageError(); - } - - public boolean tryAdvance(Consumer userAction) { - throw new LinkageError(); - } - - public Spliterator trySplit() { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/HeapByteBuffer.java b/approximations/src/main/java/stub/java/util/HeapByteBuffer.java new file mode 100644 index 00000000..31a1ee2b --- /dev/null +++ b/approximations/src/main/java/stub/java/util/HeapByteBuffer.java @@ -0,0 +1,211 @@ +package stub.java.util; + +import java.nio.*; + +public class HeapByteBuffer { + HeapByteBuffer(int cap, int lim) { + throw new LinkageError(); + } + + HeapByteBuffer(byte[] buf, int off, int len) { + throw new LinkageError(); + } + + protected HeapByteBuffer(byte[] buf, int mark, int pos, int lim, int cap, int off) { + throw new LinkageError(); + } + + public ByteBuffer slice() { + throw new LinkageError(); + } + + public ByteBuffer slice(int index, int length) { + throw new LinkageError(); + } + + public ByteBuffer duplicate() { + throw new LinkageError(); + } + + public ByteBuffer asReadOnlyBuffer() { + throw new LinkageError(); + } + + public byte get() { + throw new LinkageError(); + } + + public byte get(int i) { + throw new LinkageError(); + } + + public ByteBuffer get(byte[] dst, int offset, int length) { + throw new LinkageError(); + } + + public ByteBuffer get(int index, byte[] dst, int offset, int length) { + throw new LinkageError(); + } + + public boolean isDirect() { + throw new LinkageError(); + } + + public boolean isReadOnly() { + throw new LinkageError(); + } + + public ByteBuffer put(byte x) { + throw new LinkageError(); + } + + public ByteBuffer put(int i, byte x) { + throw new LinkageError(); + } + + public ByteBuffer put(byte[] src, int offset, int length) { + throw new LinkageError(); + } + + public ByteBuffer put(ByteBuffer src) { + throw new LinkageError(); + } + + public ByteBuffer put(int index, ByteBuffer src, int offset, int length) { + throw new LinkageError(); + } + + public ByteBuffer put(int index, byte[] src, int offset, int length) { + throw new LinkageError(); + } + + public ByteBuffer compact() { + throw new LinkageError(); + } + + byte _get(int i) { // package-private + throw new LinkageError(); + } + + void _put(int i, byte b) { + throw new LinkageError(); + } + + public char getChar() { + throw new LinkageError(); + } + + public char getChar(int i) { + throw new LinkageError(); + } + + public ByteBuffer putChar(char x) { throw new LinkageError(); } + + public ByteBuffer putChar(int i, char x) { + throw new LinkageError(); + } + + public CharBuffer asCharBuffer() { + throw new LinkageError(); + } + + public short getShort() { + throw new LinkageError(); + } + + public short getShort(int i) { + throw new LinkageError(); + } + + public ByteBuffer putShort(short x) { + throw new LinkageError(); + } + + public ByteBuffer putShort(int i, short x) { + throw new LinkageError(); + } + + public ShortBuffer asShortBuffer() { + throw new LinkageError(); + } + + public int getInt() { + throw new LinkageError(); + } + + public int getInt(int i) { + throw new LinkageError(); + } + + public ByteBuffer putInt(int x) { + throw new LinkageError(); + } + + public ByteBuffer putInt(int i, int x) { + throw new LinkageError(); + } + + public IntBuffer asIntBuffer() { + throw new LinkageError(); + } + + public long getLong() { + throw new LinkageError(); + } + + public long getLong(int i) { + throw new LinkageError(); + } + + public ByteBuffer putLong(long x) { + throw new LinkageError(); + } + + public ByteBuffer putLong(int i, long x) { + throw new LinkageError(); + } + + public LongBuffer asLongBuffer() { + throw new LinkageError(); + } + + public float getFloat() { + throw new LinkageError(); + } + + public float getFloat(int i) { + throw new LinkageError(); + } + + public ByteBuffer putFloat(float x) { + throw new LinkageError(); + } + + public ByteBuffer putFloat(int i, float x) { + throw new LinkageError(); + } + + public FloatBuffer asFloatBuffer() { + throw new LinkageError(); + } + + public double getDouble() { + throw new LinkageError(); + } + + public double getDouble(int i) { + throw new LinkageError(); + } + + public ByteBuffer putDouble(double x) { + throw new LinkageError(); + } + + public ByteBuffer putDouble(int i, double x) { + throw new LinkageError(); + } + + public DoubleBuffer asDoubleBuffer() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/HeapByteBufferR.java b/approximations/src/main/java/stub/java/util/HeapByteBufferR.java new file mode 100644 index 00000000..a49be452 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/HeapByteBufferR.java @@ -0,0 +1,141 @@ +package stub.java.util; + +import java.nio.*; + +public class HeapByteBufferR { + HeapByteBufferR(int cap, int lim) { + throw new LinkageError(); + } + + HeapByteBufferR(byte[] buf, int off, int len) { + throw new LinkageError(); + } + + protected HeapByteBufferR(byte[] buf, int mark, int pos, int lim, int cap, int off) { + throw new LinkageError(); + } + + public ByteBuffer slice() { + throw new LinkageError(); + } + + public ByteBuffer slice(int index, int length) { + throw new LinkageError(); + } + + public ByteBuffer duplicate() { + throw new LinkageError(); + } + + public ByteBuffer asReadOnlyBuffer() { + throw new LinkageError(); + } + + public boolean isReadOnly() { + throw new LinkageError(); + } + + public ByteBuffer put(byte x) { + throw new LinkageError(); + } + + public ByteBuffer put(int i, byte x) { + throw new LinkageError(); + } + + public ByteBuffer put(byte[] src, int offset, int length) { + throw new LinkageError(); + } + + public ByteBuffer put(ByteBuffer src) { + throw new LinkageError(); + } + + public ByteBuffer put(int index, ByteBuffer src, int offset, int length) { + throw new LinkageError(); + } + + public ByteBuffer put(int index, byte[] src, int offset, int length) { + throw new LinkageError(); + } + + public ByteBuffer compact() { + throw new LinkageError(); + } + + void _put(int i, byte b) { + throw new LinkageError(); + } + + public ByteBuffer putChar(char x) { + throw new LinkageError(); + } + + public ByteBuffer putChar(int i, char x) { + throw new LinkageError(); + } + + public CharBuffer asCharBuffer() { + throw new LinkageError(); + } + + public ByteBuffer putShort(short x) { + throw new LinkageError(); + } + + public ByteBuffer putShort(int i, short x) { + throw new LinkageError(); + } + + public ShortBuffer asShortBuffer() { + throw new LinkageError(); + } + + public ByteBuffer putInt(int x) { + throw new LinkageError(); + } + + public ByteBuffer putInt(int i, int x) { + throw new LinkageError(); + } + + public IntBuffer asIntBuffer() { + throw new LinkageError(); + } + + public ByteBuffer putLong(long x) { + throw new LinkageError(); + } + + public ByteBuffer putLong(int i, long x) { + throw new LinkageError(); + } + + public LongBuffer asLongBuffer() { + throw new LinkageError(); + } + + public ByteBuffer putFloat(float x) { + throw new LinkageError(); + } + + public ByteBuffer putFloat(int i, float x) { + throw new LinkageError(); + } + + public FloatBuffer asFloatBuffer() { + throw new LinkageError(); + } + + public ByteBuffer putDouble(double x) { + throw new LinkageError(); + } + + public ByteBuffer putDouble(int i, double x) { + throw new LinkageError(); + } + + public DoubleBuffer asDoubleBuffer() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/HeapCharBuffer.java b/approximations/src/main/java/stub/java/util/HeapCharBuffer.java new file mode 100644 index 00000000..4ef7876b --- /dev/null +++ b/approximations/src/main/java/stub/java/util/HeapCharBuffer.java @@ -0,0 +1,110 @@ +package stub.java.util; + +import java.nio.ByteOrder; +import java.nio.CharBuffer; + +public class HeapCharBuffer { + HeapCharBuffer(int cap, int lim) { + throw new LinkageError(); + } + + HeapCharBuffer(char[] buf, int off, int len) { + throw new LinkageError(); + } + + protected HeapCharBuffer(char[] buf, int mark, int pos, int lim, int cap, int off) { + throw new LinkageError(); + } + + public CharBuffer slice() { + throw new LinkageError(); + } + + public CharBuffer slice(int index, int length) { + throw new LinkageError(); + } + + public CharBuffer duplicate() { + throw new LinkageError(); + } + + public CharBuffer asReadOnlyBuffer() { + throw new LinkageError(); + } + + public char get() { + throw new LinkageError(); + } + + public char get(int i) { + throw new LinkageError(); + } + + char getUnchecked(int i) { + throw new LinkageError(); + } + + public CharBuffer get(char[] dst, int offset, int length) { + throw new LinkageError(); + } + + public CharBuffer get(int index, char[] dst, int offset, int length) { + throw new LinkageError(); + } + + public boolean isDirect() { + throw new LinkageError(); + } + + public boolean isReadOnly() { + throw new LinkageError(); + } + + public CharBuffer put(char x) { + throw new LinkageError(); + } + + public CharBuffer put(int i, char x) { + throw new LinkageError(); + } + + public CharBuffer put(char[] src, int offset, int length) { + throw new LinkageError(); + } + + public CharBuffer put(CharBuffer src) { + throw new LinkageError(); + } + + public CharBuffer put(int index, CharBuffer src, int offset, int length) { + throw new LinkageError(); + } + + public CharBuffer put(int index, char[] src, int offset, int length) { + throw new LinkageError(); + } + + public CharBuffer put(String src, int start, int end) { + throw new LinkageError(); + } + + public CharBuffer compact() { + throw new LinkageError(); + } + + String toString(int start, int end) { + throw new LinkageError(); + } + + public CharBuffer subSequence(int start, int end) { + throw new LinkageError(); + } + + public ByteOrder order() { + throw new LinkageError(); + } + + ByteOrder charRegionOrder() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/HeapCharBufferR.java b/approximations/src/main/java/stub/java/util/HeapCharBufferR.java new file mode 100644 index 00000000..fb38cd9e --- /dev/null +++ b/approximations/src/main/java/stub/java/util/HeapCharBufferR.java @@ -0,0 +1,86 @@ +package stub.java.util; + +import java.nio.ByteOrder; +import java.nio.CharBuffer; + +public class HeapCharBufferR { + HeapCharBufferR(int cap, int lim) { + throw new LinkageError(); + } + + HeapCharBufferR(char[] buf, int off, int len) { + throw new LinkageError(); + } + + protected HeapCharBufferR(char[] buf, int mark, int pos, int lim, int cap, int off) { + throw new LinkageError(); + } + + public CharBuffer slice() { + throw new LinkageError(); + } + + public CharBuffer slice(int index, int length) { + throw new LinkageError(); + } + + public CharBuffer duplicate() { + throw new LinkageError(); + } + + public CharBuffer asReadOnlyBuffer() { + throw new LinkageError(); + } + + public boolean isReadOnly() { + throw new LinkageError(); + } + + public CharBuffer put(char x) { + throw new LinkageError(); + } + + public CharBuffer put(int i, char x) { + throw new LinkageError(); + } + + public CharBuffer put(char[] src, int offset, int length) { + throw new LinkageError(); + } + + public CharBuffer put(CharBuffer src) { + throw new LinkageError(); + } + + public CharBuffer put(int index, CharBuffer src, int offset, int length) { + throw new LinkageError(); + } + + public CharBuffer put(int index, char[] src, int offset, int length) { + throw new LinkageError(); + } + + public CharBuffer put(String src, int start, int end) { + throw new LinkageError(); + } + + public CharBuffer compact() { + throw new LinkageError(); + } + + String toString(int start, int end) { + throw new LinkageError(); + } + + public CharBuffer subSequence(int start, int end) { + throw new LinkageError(); + } + + public ByteOrder order() { + throw new LinkageError(); + } + + ByteOrder charRegionOrder() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/HeapFloatBuffer.java b/approximations/src/main/java/stub/java/util/HeapFloatBuffer.java new file mode 100644 index 00000000..d1d2fdca --- /dev/null +++ b/approximations/src/main/java/stub/java/util/HeapFloatBuffer.java @@ -0,0 +1,90 @@ +package stub.java.util; + +import java.nio.ByteOrder; +import java.nio.FloatBuffer; + +public class HeapFloatBuffer { + HeapFloatBuffer(int cap, int lim) { + throw new LinkageError(); + } + + HeapFloatBuffer(float[] buf, int off, int len) { + throw new LinkageError(); + } + + protected HeapFloatBuffer(float[] buf, int mark, int pos, int lim, int cap, int off) { + throw new LinkageError(); + } + + public FloatBuffer slice() { + throw new LinkageError(); + } + + public FloatBuffer slice(int index, int length) { + throw new LinkageError(); + } + + public FloatBuffer duplicate() { + throw new LinkageError(); + } + + public FloatBuffer asReadOnlyBuffer() { + throw new LinkageError(); + } + + public float get() { + throw new LinkageError(); + } + + public float get(int i) { + throw new LinkageError(); + } + + public FloatBuffer get(float[] dst, int offset, int length) { + throw new LinkageError(); + } + + public FloatBuffer get(int index, float[] dst, int offset, int length) { + throw new LinkageError(); + } + + public boolean isDirect() { + throw new LinkageError(); + } + + public boolean isReadOnly() { + throw new LinkageError(); + } + + public FloatBuffer put(float x) { + throw new LinkageError(); + } + + public FloatBuffer put(int i, float x) { + throw new LinkageError(); + } + + public FloatBuffer put(float[] src, int offset, int length) { + throw new LinkageError(); + } + + public FloatBuffer put(FloatBuffer src) { + throw new LinkageError(); + } + + public FloatBuffer put(int index, FloatBuffer src, int offset, int length) { + throw new LinkageError(); + } + + public FloatBuffer put(int index, float[] src, int offset, int length) { + throw new LinkageError(); + } + + public FloatBuffer compact() { + throw new LinkageError(); + } + + public ByteOrder order() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/HeapIntBuffer.java b/approximations/src/main/java/stub/java/util/HeapIntBuffer.java new file mode 100644 index 00000000..f47f921c --- /dev/null +++ b/approximations/src/main/java/stub/java/util/HeapIntBuffer.java @@ -0,0 +1,90 @@ +package stub.java.util; + +import java.nio.ByteOrder; +import java.nio.IntBuffer; + +public class HeapIntBuffer { + HeapIntBuffer(int cap, int lim) { + throw new LinkageError(); + } + + HeapIntBuffer(int[] buf, int off, int len) { + throw new LinkageError(); + } + + protected HeapIntBuffer(int[] buf, int mark, int pos, int lim, int cap, int off) { + throw new LinkageError(); + } + + public IntBuffer slice() { + throw new LinkageError(); + } + + public IntBuffer slice(int index, int length) { + throw new LinkageError(); + } + + public IntBuffer duplicate() { + throw new LinkageError(); + } + + public IntBuffer asReadOnlyBuffer() { + throw new LinkageError(); + } + + public int get() { + throw new LinkageError(); + } + + public int get(int i) { + throw new LinkageError(); + } + + public IntBuffer get(int[] dst, int offset, int length) { + throw new LinkageError(); + } + + public IntBuffer get(int index, int[] dst, int offset, int length) { + throw new LinkageError(); + } + + public boolean isDirect() { + throw new LinkageError(); + } + + public boolean isReadOnly() { + throw new LinkageError(); + } + + public IntBuffer put(int x) { + throw new LinkageError(); + } + + public IntBuffer put(int i, int x) { + throw new LinkageError(); + } + + public IntBuffer put(int[] src, int offset, int length) { + throw new LinkageError(); + } + + public IntBuffer put(IntBuffer src) { + throw new LinkageError(); + } + + public IntBuffer put(int index, IntBuffer src, int offset, int length) { + throw new LinkageError(); + } + + public IntBuffer put(int index, int[] src, int offset, int length) { + throw new LinkageError(); + } + + public IntBuffer compact() { + throw new LinkageError(); + } + + public ByteOrder order() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/HeapIntBufferR.java b/approximations/src/main/java/stub/java/util/HeapIntBufferR.java new file mode 100644 index 00000000..2bf830d4 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/HeapIntBufferR.java @@ -0,0 +1,70 @@ +package stub.java.util; + +import java.nio.ByteOrder; +import java.nio.IntBuffer; + +public class HeapIntBufferR { + HeapIntBufferR(int cap, int lim) { + throw new LinkageError(); + } + + HeapIntBufferR(int[] buf, int off, int len) { + throw new LinkageError(); + } + + protected HeapIntBufferR(int[] buf, int mark, int pos, int lim, int cap, int off) { + throw new LinkageError(); + } + + public IntBuffer slice() { + throw new LinkageError(); + } + + public IntBuffer slice(int index, int length) { + throw new LinkageError(); + } + + public IntBuffer duplicate() { + throw new LinkageError(); + } + + public IntBuffer asReadOnlyBuffer() { + throw new LinkageError(); + } + + public boolean isReadOnly() { + throw new LinkageError(); + } + + public IntBuffer put(int x) { + throw new LinkageError(); + } + + public IntBuffer put(int i, int x) { + throw new LinkageError(); + } + + public IntBuffer put(int[] src, int offset, int length) { + throw new LinkageError(); + } + + public IntBuffer put(IntBuffer src) { + throw new LinkageError(); + } + + public IntBuffer put(int index, IntBuffer src, int offset, int length) { + throw new LinkageError(); + } + + public IntBuffer put(int index, int[] src, int offset, int length) { + throw new LinkageError(); + } + + public IntBuffer compact() { + throw new LinkageError(); + } + + public ByteOrder order() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/LinkedHashSet_KeyIterator.java b/approximations/src/main/java/stub/java/util/LinkedHashSet_KeyIterator.java deleted file mode 100644 index 287bb47f..00000000 --- a/approximations/src/main/java/stub/java/util/LinkedHashSet_KeyIterator.java +++ /dev/null @@ -1,41 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/LinkedHashSet.lsl:39 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.HashMap; -import java.util.Iterator; -import java.util.function.Consumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class LinkedHashSet_KeyIterator implements LibSLRuntime.HasAutomaton, Iterator { - private LinkedHashSet_KeyIterator(Void a, Void b) { - super(); - } - - private LinkedHashSet_KeyIterator(HashMap source) { - throw new LinkageError(); - } - - public boolean hasNext() { - throw new LinkageError(); - } - - public final Object next() { - throw new LinkageError(); - } - - public void remove() { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer userAction) { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/LinkedHashSet_KeySpliterator.java b/approximations/src/main/java/stub/java/util/LinkedHashSet_KeySpliterator.java deleted file mode 100644 index dc299af5..00000000 --- a/approximations/src/main/java/stub/java/util/LinkedHashSet_KeySpliterator.java +++ /dev/null @@ -1,45 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/LinkedHashSet.lsl:31 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.HashMap; -import java.util.Spliterator; -import java.util.function.Consumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class LinkedHashSet_KeySpliterator implements LibSLRuntime.HasAutomaton, Spliterator { - private LinkedHashSet_KeySpliterator(Void a, Void b) { - super(); - } - - private LinkedHashSet_KeySpliterator(HashMap source, int origin, int fence, int est, - int expectedModCount) { - throw new LinkageError(); - } - - public long estimateSize() { - throw new LinkageError(); - } - - public int characteristics() { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer userAction) { - throw new LinkageError(); - } - - public boolean tryAdvance(Consumer userAction) { - throw new LinkageError(); - } - - public Spliterator trySplit() { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/LinkedList_DescendingIterator.java b/approximations/src/main/java/stub/java/util/LinkedList_DescendingIterator.java deleted file mode 100644 index 37a2b9e2..00000000 --- a/approximations/src/main/java/stub/java/util/LinkedList_DescendingIterator.java +++ /dev/null @@ -1,36 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/LinkedList.lsl:43 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Iterator; -import java.util.function.Consumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class LinkedList_DescendingIterator implements LibSLRuntime.HasAutomaton, Iterator { - private LinkedList_DescendingIterator(Void a, Void b) { - super(); - } - - public boolean hasNext() { - throw new LinkageError(); - } - - public Object next() { - throw new LinkageError(); - } - - public void remove() { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer userAction) { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/LinkedList_ListItr.java b/approximations/src/main/java/stub/java/util/LinkedList_ListItr.java deleted file mode 100644 index 2df0b3b3..00000000 --- a/approximations/src/main/java/stub/java/util/LinkedList_ListItr.java +++ /dev/null @@ -1,60 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/LinkedList.lsl:34 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ListIterator; -import java.util.function.Consumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class LinkedList_ListItr implements LibSLRuntime.HasAutomaton, ListIterator { - private LinkedList_ListItr(Void a, Void b) { - super(); - } - - public boolean hasPrevious() { - throw new LinkageError(); - } - - public int nextIndex() { - throw new LinkageError(); - } - - public int previousIndex() { - throw new LinkageError(); - } - - public boolean hasNext() { - throw new LinkageError(); - } - - public Object next() { - throw new LinkageError(); - } - - public Object previous() { - throw new LinkageError(); - } - - public void remove() { - throw new LinkageError(); - } - - public void set(Object e) { - throw new LinkageError(); - } - - public void add(Object e) { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer userAction) { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/LinkedList_Spliterator.java b/approximations/src/main/java/stub/java/util/LinkedList_Spliterator.java deleted file mode 100644 index 3fb5d733..00000000 --- a/approximations/src/main/java/stub/java/util/LinkedList_Spliterator.java +++ /dev/null @@ -1,48 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/LinkedList.lsl:52 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.LinkedList; -import java.util.Spliterator; -import java.util.function.Consumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class LinkedList_Spliterator implements LibSLRuntime.HasAutomaton, Spliterator { - private LinkedList_Spliterator(Void a, Void b) { - super(); - } - - private LinkedList_Spliterator(LinkedList _this, int origin, int fence, int expectedModCount) { - throw new LinkageError(); - } - - public int characteristics() { - throw new LinkageError(); - } - - public long estimateSize() { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer _action) { - throw new LinkageError(); - } - - public long getExactSizeIfKnown() { - throw new LinkageError(); - } - - public boolean tryAdvance(Consumer _action) { - throw new LinkageError(); - } - - public Spliterator trySplit() { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/LinkedList_SubList$ListIterator.java b/approximations/src/main/java/stub/java/util/LinkedList_SubList$ListIterator.java deleted file mode 100644 index a9332419..00000000 --- a/approximations/src/main/java/stub/java/util/LinkedList_SubList$ListIterator.java +++ /dev/null @@ -1,60 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/LinkedList.lsl:82 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.ListIterator; -import java.util.function.Consumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class LinkedList_SubList$ListIterator implements LibSLRuntime.HasAutomaton, ListIterator { - private LinkedList_SubList$ListIterator(Void a, Void b) { - super(); - } - - public boolean hasPrevious() { - throw new LinkageError(); - } - - public int nextIndex() { - throw new LinkageError(); - } - - public int previousIndex() { - throw new LinkageError(); - } - - public boolean hasNext() { - throw new LinkageError(); - } - - public Object next() { - throw new LinkageError(); - } - - public Object previous() { - throw new LinkageError(); - } - - public void remove() { - throw new LinkageError(); - } - - public void set(Object e) { - throw new LinkageError(); - } - - public void add(Object e) { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer userAction) { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/LinkedList_SubList$Spliterator.java b/approximations/src/main/java/stub/java/util/LinkedList_SubList$Spliterator.java deleted file mode 100644 index defcd7d6..00000000 --- a/approximations/src/main/java/stub/java/util/LinkedList_SubList$Spliterator.java +++ /dev/null @@ -1,43 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/LinkedList.lsl:72 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Spliterator; -import java.util.function.Consumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class LinkedList_SubList$Spliterator implements LibSLRuntime.HasAutomaton, Spliterator { - private LinkedList_SubList$Spliterator(Void a, Void b) { - super(); - } - - public int characteristics() { - throw new LinkageError(); - } - - public long estimateSize() { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer _action) { - throw new LinkageError(); - } - - public long getExactSizeIfKnown() { - throw new LinkageError(); - } - - public boolean tryAdvance(Consumer _action) { - throw new LinkageError(); - } - - public Spliterator trySplit() { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/LinkedList_SubList.java b/approximations/src/main/java/stub/java/util/LinkedList_SubList.java deleted file mode 100644 index 8947d0c9..00000000 --- a/approximations/src/main/java/stub/java/util/LinkedList_SubList.java +++ /dev/null @@ -1,177 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/LinkedList.lsl:61 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.Object; -import java.lang.String; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.AbstractList; -import java.util.Collection; -import java.util.Comparator; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; -import java.util.RandomAccess; -import java.util.Spliterator; -import java.util.function.Consumer; -import java.util.function.IntFunction; -import java.util.function.Predicate; -import java.util.function.UnaryOperator; -import java.util.stream.Stream; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class LinkedList_SubList extends AbstractList implements LibSLRuntime.HasAutomaton, List, RandomAccess { - private LinkedList_SubList(Void a, Void b) { - super(); - } - - public LinkedList_SubList(LinkedList root, int fromIndex, int toIndex) { - throw new LinkageError(); - } - - private LinkedList_SubList(LinkedList_SubList parent, int fromIndex, int toIndex) { - throw new LinkageError(); - } - - public boolean add(Object e) { - throw new LinkageError(); - } - - public void add(int index, Object element) { - throw new LinkageError(); - } - - public boolean addAll(Collection c) { - throw new LinkageError(); - } - - public boolean addAll(int index, Collection c) { - throw new LinkageError(); - } - - public void clear() { - throw new LinkageError(); - } - - public boolean contains(Object o) { - throw new LinkageError(); - } - - public boolean containsAll(Collection c) { - throw new LinkageError(); - } - - public boolean equals(Object o) { - throw new LinkageError(); - } - - public void forEach(Consumer _action) { - throw new LinkageError(); - } - - public Object get(int index) { - throw new LinkageError(); - } - - public int hashCode() { - throw new LinkageError(); - } - - public int indexOf(Object o) { - throw new LinkageError(); - } - - public boolean isEmpty() { - throw new LinkageError(); - } - - public Iterator iterator() { - throw new LinkageError(); - } - - public int lastIndexOf(Object o) { - throw new LinkageError(); - } - - public ListIterator listIterator() { - throw new LinkageError(); - } - - public ListIterator listIterator(int index) { - throw new LinkageError(); - } - - public Stream parallelStream() { - throw new LinkageError(); - } - - public boolean remove(Object o) { - throw new LinkageError(); - } - - public Object remove(int index) { - throw new LinkageError(); - } - - public boolean removeAll(Collection c) { - throw new LinkageError(); - } - - public boolean removeIf(Predicate filter) { - throw new LinkageError(); - } - - public void replaceAll(UnaryOperator operator) { - throw new LinkageError(); - } - - public boolean retainAll(Collection c) { - throw new LinkageError(); - } - - public Object set(int index, Object element) { - throw new LinkageError(); - } - - public int size() { - throw new LinkageError(); - } - - public void sort(Comparator c) { - throw new LinkageError(); - } - - public Spliterator spliterator() { - throw new LinkageError(); - } - - public Stream stream() { - throw new LinkageError(); - } - - public List subList(int fromIndex, int toIndex) { - throw new LinkageError(); - } - - public Object[] toArray() { - throw new LinkageError(); - } - - public Object[] toArray(IntFunction generator) { - throw new LinkageError(); - } - - public Object[] toArray(Object[] a) { - throw new LinkageError(); - } - - public String toString() { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/Spliterators_ArraySpliterator.java b/approximations/src/main/java/stub/java/util/Spliterators_ArraySpliterator.java deleted file mode 100644 index 6f779567..00000000 --- a/approximations/src/main/java/stub/java/util/Spliterators_ArraySpliterator.java +++ /dev/null @@ -1,62 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/Spliterators.lsl:44 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Comparator; -import java.util.Spliterator; -import java.util.function.Consumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class Spliterators_ArraySpliterator implements LibSLRuntime.HasAutomaton, Spliterator { - private Spliterators_ArraySpliterator(Void a, Void b) { - super(); - } - - public Spliterators_ArraySpliterator(Object[] arr, int additionalCharacteristics) { - throw new LinkageError(); - } - - public Spliterators_ArraySpliterator(Object[] arr, int origin, int pFence, - int additionalCharacteristics) { - throw new LinkageError(); - } - - public int characteristics() { - throw new LinkageError(); - } - - public long estimateSize() { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer _action) { - throw new LinkageError(); - } - - public Comparator getComparator() { - throw new LinkageError(); - } - - public long getExactSizeIfKnown() { - throw new LinkageError(); - } - - public boolean hasCharacteristics(int _characteristics) { - throw new LinkageError(); - } - - public boolean tryAdvance(Consumer _action) { - throw new LinkageError(); - } - - public Spliterator trySplit() { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/Spliterators_DoubleArraySpliterator.java b/approximations/src/main/java/stub/java/util/Spliterators_DoubleArraySpliterator.java deleted file mode 100644 index 66522e36..00000000 --- a/approximations/src/main/java/stub/java/util/Spliterators_DoubleArraySpliterator.java +++ /dev/null @@ -1,70 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/Spliterators.lsl:53 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Comparator; -import java.util.Spliterator; -import java.util.function.Consumer; -import java.util.function.DoubleConsumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class Spliterators_DoubleArraySpliterator implements LibSLRuntime.HasAutomaton, Spliterator.OfDouble { - private Spliterators_DoubleArraySpliterator(Void a, Void b) { - super(); - } - - public Spliterators_DoubleArraySpliterator(double[] arr, int additionalCharacteristics) { - throw new LinkageError(); - } - - public Spliterators_DoubleArraySpliterator(double[] arr, int origin, int pFence, - int additionalCharacteristics) { - throw new LinkageError(); - } - - public int characteristics() { - throw new LinkageError(); - } - - public long estimateSize() { - throw new LinkageError(); - } - - public void forEachRemaining(DoubleConsumer _action) { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer _action) { - throw new LinkageError(); - } - - public Comparator getComparator() { - throw new LinkageError(); - } - - public long getExactSizeIfKnown() { - throw new LinkageError(); - } - - public boolean hasCharacteristics(int _characteristics) { - throw new LinkageError(); - } - - public boolean tryAdvance(DoubleConsumer _action) { - throw new LinkageError(); - } - - public boolean tryAdvance(Consumer _action) { - throw new LinkageError(); - } - - public Spliterator.OfDouble trySplit() { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/Spliterators_IntArraySpliterator.java b/approximations/src/main/java/stub/java/util/Spliterators_IntArraySpliterator.java deleted file mode 100644 index 45a90c3f..00000000 --- a/approximations/src/main/java/stub/java/util/Spliterators_IntArraySpliterator.java +++ /dev/null @@ -1,70 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/Spliterators.lsl:62 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Comparator; -import java.util.Spliterator; -import java.util.function.Consumer; -import java.util.function.IntConsumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class Spliterators_IntArraySpliterator implements LibSLRuntime.HasAutomaton, Spliterator.OfInt { - private Spliterators_IntArraySpliterator(Void a, Void b) { - super(); - } - - public Spliterators_IntArraySpliterator(int[] arr, int additionalCharacteristics) { - throw new LinkageError(); - } - - public Spliterators_IntArraySpliterator(int[] arr, int origin, int pFence, - int additionalCharacteristics) { - throw new LinkageError(); - } - - public int characteristics() { - throw new LinkageError(); - } - - public long estimateSize() { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer _action) { - throw new LinkageError(); - } - - public void forEachRemaining(IntConsumer _action) { - throw new LinkageError(); - } - - public Comparator getComparator() { - throw new LinkageError(); - } - - public long getExactSizeIfKnown() { - throw new LinkageError(); - } - - public boolean hasCharacteristics(int _characteristics) { - throw new LinkageError(); - } - - public boolean tryAdvance(IntConsumer _action) { - throw new LinkageError(); - } - - public boolean tryAdvance(Consumer _action) { - throw new LinkageError(); - } - - public Spliterator.OfInt trySplit() { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/Spliterators_LongArraySpliterator.java b/approximations/src/main/java/stub/java/util/Spliterators_LongArraySpliterator.java deleted file mode 100644 index 8bde7189..00000000 --- a/approximations/src/main/java/stub/java/util/Spliterators_LongArraySpliterator.java +++ /dev/null @@ -1,70 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/Spliterators.lsl:71 -// -package stub.java.util; - -import java.lang.LinkageError; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Comparator; -import java.util.Spliterator; -import java.util.function.Consumer; -import java.util.function.LongConsumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class Spliterators_LongArraySpliterator implements LibSLRuntime.HasAutomaton, Spliterator.OfLong { - private Spliterators_LongArraySpliterator(Void a, Void b) { - super(); - } - - public Spliterators_LongArraySpliterator(long[] arr, int additionalCharacteristics) { - throw new LinkageError(); - } - - public Spliterators_LongArraySpliterator(long[] arr, int origin, int pFence, - int additionalCharacteristics) { - throw new LinkageError(); - } - - public int characteristics() { - throw new LinkageError(); - } - - public long estimateSize() { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer _action) { - throw new LinkageError(); - } - - public void forEachRemaining(LongConsumer _action) { - throw new LinkageError(); - } - - public Comparator getComparator() { - throw new LinkageError(); - } - - public long getExactSizeIfKnown() { - throw new LinkageError(); - } - - public boolean hasCharacteristics(int _characteristics) { - throw new LinkageError(); - } - - public boolean tryAdvance(LongConsumer _action) { - throw new LinkageError(); - } - - public boolean tryAdvance(Consumer _action) { - throw new LinkageError(); - } - - public Spliterator.OfLong trySplit() { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/array/AbstractArrayIterator.java b/approximations/src/main/java/stub/java/util/array/AbstractArrayIterator.java new file mode 100644 index 00000000..04add8c0 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/array/AbstractArrayIterator.java @@ -0,0 +1,43 @@ +package stub.java.util.array; + +import stub.java.util.AbstractIterator; + +import java.util.function.Consumer; + +public abstract class AbstractArrayIterator extends AbstractIterator { + + @SuppressWarnings("unused") + AbstractArrayIterator(int cursor) { + super(0); + throw new LinkageError(); + } + + protected final int _parentModCount() { + throw new LinkageError(); + } + + abstract protected int _getLength(); + + abstract protected E _getItem(int index); + + @SuppressWarnings("unused") + protected boolean _isEmpty() { + throw new LinkageError(); + } + + public boolean hasNext() { + throw new LinkageError(); + } + + public E next() { + throw new LinkageError(); + } + + public void remove() { + throw new LinkageError(); + } + + public void forEachRemaining(Consumer userAction) { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/array/AbstractArraySpliterator.java b/approximations/src/main/java/stub/java/util/array/AbstractArraySpliterator.java new file mode 100644 index 00000000..659d9058 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/array/AbstractArraySpliterator.java @@ -0,0 +1,64 @@ +package stub.java.util.array; + +import java.util.Comparator; +import java.util.Spliterators; +import java.util.function.Consumer; + +@SuppressWarnings("unused") +public abstract class AbstractArraySpliterator extends Spliterators.AbstractSpliterator { + + public AbstractArraySpliterator(int index, int fence, int characteristics) { + super(fence - index, characteristics); + throw new LinkageError(); + } + + protected int _parentModCount() { + throw new LinkageError(); + } + + protected int _storageSize() { + throw new LinkageError(); + } + + protected int _getFence() { + throw new LinkageError(); + } + + protected void _checkForModification() { + throw new LinkageError(); + } + + public boolean hasCharacteristics(int _characteristics) { + throw new LinkageError(); + } + + public int characteristics() { + throw new LinkageError(); + } + + public long estimateSize() { + throw new LinkageError(); + } + + abstract protected E _getItem(int index); + + public void forEachRemaining(Consumer _action) { + throw new LinkageError(); + } + + public Comparator getComparator() { + throw new LinkageError(); + } + + public long getExactSizeIfKnown() { + throw new LinkageError(); + } + + public boolean tryAdvance(Consumer _action) { + throw new LinkageError(); + } + + public AbstractArraySpliterator trySplit() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/array/ArrayIterator.java b/approximations/src/main/java/stub/java/util/array/ArrayIterator.java new file mode 100644 index 00000000..aef2b49f --- /dev/null +++ b/approximations/src/main/java/stub/java/util/array/ArrayIterator.java @@ -0,0 +1,46 @@ +package stub.java.util.array; + +import java.util.function.Consumer; + +public class ArrayIterator extends AbstractArrayIterator { + + @SuppressWarnings("unused") + public ArrayIterator(E[] storage, int cursor) { + super(cursor); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public ArrayIterator(E[] storage) { + this(storage, 0); + throw new LinkageError(); + } + + protected int _getLength() { + throw new LinkageError(); + } + + protected E _getItem(int index) { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public boolean hasNext() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public E next() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public void remove() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public void forEachRemaining(Consumer userAction) { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/array/ArraySpliterator.java b/approximations/src/main/java/stub/java/util/array/ArraySpliterator.java new file mode 100644 index 00000000..2fae85be --- /dev/null +++ b/approximations/src/main/java/stub/java/util/array/ArraySpliterator.java @@ -0,0 +1,69 @@ +package stub.java.util.array; + +import java.lang.LinkageError; +import java.lang.Object; +import java.lang.SuppressWarnings; +import java.util.Comparator; +import java.util.function.Consumer; + +public final class ArraySpliterator extends AbstractArraySpliterator { + + @SuppressWarnings("unused") + public ArraySpliterator(E[] array, int index, int fence, int characteristics) { + super(index, fence, characteristics); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public ArraySpliterator(E[] arr, int additionalCharacteristics) { + this(arr, 0, -1, additionalCharacteristics); + throw new LinkageError(); + } + + @SuppressWarnings({"ProtectedMemberInFinalClass", "unused"}) + protected ArraySpliterator _create(int index, int fence) { + throw new LinkageError(); + } + + protected E _getItem(int index) { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public int characteristics() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public long estimateSize() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public void forEachRemaining(Consumer action) { + throw new LinkageError(); + } + + public Comparator getComparator() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public long getExactSizeIfKnown() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public boolean hasCharacteristics(int _characteristics) { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public boolean tryAdvance(Consumer action) { + throw new LinkageError(); + } + + public ArraySpliterator trySplit() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/array/DoubleArrayIterator.java b/approximations/src/main/java/stub/java/util/array/DoubleArrayIterator.java new file mode 100644 index 00000000..4d720e01 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/array/DoubleArrayIterator.java @@ -0,0 +1,54 @@ +package stub.java.util.array; + +import java.util.PrimitiveIterator; +import java.util.function.Consumer; +import java.util.function.DoubleConsumer; + +public class DoubleArrayIterator extends AbstractArrayIterator implements PrimitiveIterator.OfDouble { + + @SuppressWarnings("unused") + public DoubleArrayIterator(double[] storage, int cursor) { + super(cursor); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public DoubleArrayIterator(double[] storage) { + this(storage, 0); + throw new LinkageError(); + } + + protected int _getLength() { + throw new LinkageError(); + } + + protected Double _getItem(int index) { + throw new LinkageError(); + } + + public boolean hasNext() { + throw new LinkageError(); + } + + public Double next() { + throw new LinkageError(); + } + + public double nextDouble() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public void remove() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public void forEachRemaining(Consumer userAction) { + throw new LinkageError(); + } + + public void forEachRemaining(DoubleConsumer action) { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/array/DoubleArraySpliterator.java b/approximations/src/main/java/stub/java/util/array/DoubleArraySpliterator.java new file mode 100644 index 00000000..48b6919f --- /dev/null +++ b/approximations/src/main/java/stub/java/util/array/DoubleArraySpliterator.java @@ -0,0 +1,74 @@ +package stub.java.util.array; + +import java.lang.LinkageError; +import java.util.Comparator; +import java.util.Spliterator; +import java.util.function.Consumer; +import java.util.function.DoubleConsumer; + +@SuppressWarnings("unused") +public final class DoubleArraySpliterator extends AbstractArraySpliterator implements Spliterator.OfDouble { + + public DoubleArraySpliterator(double[] array, int index, int fence, int characteristics) { + super(index, fence, characteristics); + throw new LinkageError(); + } + + public DoubleArraySpliterator(double[] arr, int additionalCharacteristics) { + this(arr, 0, -1, additionalCharacteristics); + throw new LinkageError(); + } + + @SuppressWarnings("ProtectedMemberInFinalClass") + protected DoubleArraySpliterator _create(int index, int fence) { + throw new LinkageError(); + } + + protected Double _getItem(int index) { + throw new LinkageError(); + } + + public int characteristics() { + throw new LinkageError(); + } + + public long estimateSize() { + throw new LinkageError(); + } + + public void forEachRemaining(DoubleConsumer _action) { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public void forEachRemaining(Consumer action) { + throw new LinkageError(); + } + + public Comparator getComparator() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public long getExactSizeIfKnown() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public boolean hasCharacteristics(int _characteristics) { + throw new LinkageError(); + } + + public boolean tryAdvance(DoubleConsumer _action) { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public boolean tryAdvance(Consumer action) { + throw new LinkageError(); + } + + public DoubleArraySpliterator trySplit() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/array/IntArrayIterator.java b/approximations/src/main/java/stub/java/util/array/IntArrayIterator.java new file mode 100644 index 00000000..4806b1e1 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/array/IntArrayIterator.java @@ -0,0 +1,54 @@ +package stub.java.util.array; + +import java.util.PrimitiveIterator; +import java.util.function.Consumer; +import java.util.function.IntConsumer; + +public class IntArrayIterator extends AbstractArrayIterator implements PrimitiveIterator.OfInt { + + @SuppressWarnings("unused") + public IntArrayIterator(int[] storage, int cursor) { + super(cursor); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public IntArrayIterator(int[] storage) { + this(storage, 0); + throw new LinkageError(); + } + + protected int _getLength() { + throw new LinkageError(); + } + + protected Integer _getItem(int index) { + throw new LinkageError(); + } + + public boolean hasNext() { + throw new LinkageError(); + } + + public Integer next() { + throw new LinkageError(); + } + + public int nextInt() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public void remove() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public void forEachRemaining(Consumer action) { + throw new LinkageError(); + } + + public void forEachRemaining(IntConsumer action) { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/array/IntArraySpliterator.java b/approximations/src/main/java/stub/java/util/array/IntArraySpliterator.java new file mode 100644 index 00000000..ba985e8a --- /dev/null +++ b/approximations/src/main/java/stub/java/util/array/IntArraySpliterator.java @@ -0,0 +1,77 @@ +package stub.java.util.array; + +import generated.java.util.array.IntArraySpliteratorImpl; + +import java.lang.LinkageError; +import java.util.Comparator; +import java.util.Spliterator; +import java.util.function.Consumer; +import java.util.function.IntConsumer; + +public final class IntArraySpliterator extends AbstractArraySpliterator implements Spliterator.OfInt { + + @SuppressWarnings("unused") + public IntArraySpliterator(int[] array, int index, int fence, int characteristics) { + super(index, fence, characteristics); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public IntArraySpliterator(int[] arr, int additionalCharacteristics) { + this(arr, 0, arr.length, additionalCharacteristics); + throw new LinkageError(); + } + + @SuppressWarnings({"ProtectedMemberInFinalClass", "unused"}) + protected IntArraySpliteratorImpl _create(int index, int fence) { + throw new LinkageError(); + } + + protected Integer _getItem(int index) { + throw new LinkageError(); + } + + public int characteristics() { + throw new LinkageError(); + } + + public long estimateSize() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public void forEachRemaining(Consumer action) { + throw new LinkageError(); + } + + public void forEachRemaining(IntConsumer action) { + throw new LinkageError(); + } + + public Comparator getComparator() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public long getExactSizeIfKnown() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public boolean hasCharacteristics(int characteristics) { + throw new LinkageError(); + } + + public boolean tryAdvance(IntConsumer action) { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public boolean tryAdvance(Consumer action) { + throw new LinkageError(); + } + + public IntArraySpliterator trySplit() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/array/LongArrayIterator.java b/approximations/src/main/java/stub/java/util/array/LongArrayIterator.java new file mode 100644 index 00000000..8930acad --- /dev/null +++ b/approximations/src/main/java/stub/java/util/array/LongArrayIterator.java @@ -0,0 +1,54 @@ +package stub.java.util.array; + +import java.util.PrimitiveIterator; +import java.util.function.Consumer; +import java.util.function.LongConsumer; + +public class LongArrayIterator extends AbstractArrayIterator implements PrimitiveIterator.OfLong { + + @SuppressWarnings("unused") + public LongArrayIterator(long[] storage, int cursor) { + super(cursor); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public LongArrayIterator(long[] storage) { + this(storage, 0); + throw new LinkageError(); + } + + protected int _getLength() { + throw new LinkageError(); + } + + protected Long _getItem(int index) { + throw new LinkageError(); + } + + public boolean hasNext() { + throw new LinkageError(); + } + + public Long next() { + throw new LinkageError(); + } + + public long nextLong() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public void remove() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public void forEachRemaining(Consumer action) { + throw new LinkageError(); + } + + public void forEachRemaining(LongConsumer action) { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/array/LongArraySpliterator.java b/approximations/src/main/java/stub/java/util/array/LongArraySpliterator.java new file mode 100644 index 00000000..466536d0 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/array/LongArraySpliterator.java @@ -0,0 +1,75 @@ +package stub.java.util.array; + +import java.lang.LinkageError; +import java.util.Comparator; +import java.util.Spliterator; +import java.util.function.Consumer; +import java.util.function.LongConsumer; + +public final class LongArraySpliterator extends AbstractArraySpliterator implements Spliterator.OfLong { + + @SuppressWarnings("unused") + public LongArraySpliterator(long[] array, int index, int fence, int characteristics) { + super(index, fence, characteristics); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public LongArraySpliterator(long[] arr, int additionalCharacteristics) { + this(arr, 0, arr.length, additionalCharacteristics); + throw new LinkageError(); + } + + @SuppressWarnings({"unused", "ProtectedMemberInFinalClass"}) + protected LongArraySpliterator _create(int index, int fence) { + throw new LinkageError(); + } + + protected Long _getItem(int index) { + throw new LinkageError(); + } + + public int characteristics() { + throw new LinkageError(); + } + + public long estimateSize() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public void forEachRemaining(Consumer action) { + throw new LinkageError(); + } + + public void forEachRemaining(LongConsumer action) { + throw new LinkageError(); + } + + public Comparator getComparator() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public long getExactSizeIfKnown() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public boolean hasCharacteristics(int characteristics) { + throw new LinkageError(); + } + + public boolean tryAdvance(LongConsumer action) { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public boolean tryAdvance(Consumer action) { + throw new LinkageError(); + } + + public LongArraySpliterator trySplit() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/list/LinkedList_DescendingIterator.java b/approximations/src/main/java/stub/java/util/list/LinkedList_DescendingIterator.java new file mode 100644 index 00000000..6e4f3e0f --- /dev/null +++ b/approximations/src/main/java/stub/java/util/list/LinkedList_DescendingIterator.java @@ -0,0 +1,34 @@ +package stub.java.util.list; + +import generated.java.util.list.LinkedListImpl; + +import java.lang.LinkageError; +import java.util.function.Consumer; + +public final class LinkedList_DescendingIterator extends ListIteratorStub { + + public LinkedList_DescendingIterator(LinkedListImpl list) { + super(list); + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public boolean hasNext() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public E next() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public void remove() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public void forEachRemaining(Consumer userAction) { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/list/ListIteratorStub.java b/approximations/src/main/java/stub/java/util/list/ListIteratorStub.java new file mode 100644 index 00000000..79bb2ea1 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/list/ListIteratorStub.java @@ -0,0 +1,88 @@ +package stub.java.util.list; + +import generated.java.util.list.AbstractListImpl; +import org.usvm.api.SymbolicList; +import stub.java.util.AbstractIterator; + +import java.lang.LinkageError; +import java.util.ListIterator; +import java.util.function.Consumer; + +public class ListIteratorStub extends AbstractIterator implements ListIterator { + + @SuppressWarnings("unused") + public ListIteratorStub(AbstractListImpl list, int index, int expectedModCount) { + super(expectedModCount); + throw new LinkageError(); + } + + public ListIteratorStub(AbstractListImpl list, int index) { + this(list, index, list.modCount); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public ListIteratorStub(AbstractListImpl list) { + this(list, 0); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + protected AbstractListImpl _getList() { + throw new LinkageError(); + } + + protected int _parentModCount() { + throw new LinkageError(); + } + + @SuppressWarnings("unused") + protected int _getSize(SymbolicList storage) { + throw new LinkageError(); + } + + public boolean hasPrevious() { + throw new LinkageError(); + } + + public int nextIndex() { + throw new LinkageError(); + } + + public int previousIndex() { + throw new LinkageError(); + } + + @SuppressWarnings("unused") + protected boolean _hasNext(int size) { + throw new LinkageError(); + } + + public boolean hasNext() { + throw new LinkageError(); + } + + public E next() { + throw new LinkageError(); + } + + public E previous() { + throw new LinkageError(); + } + + public void remove() { + throw new LinkageError(); + } + + public void set(E e) { + throw new LinkageError(); + } + + public void add(E e) { + throw new LinkageError(); + } + + public void forEachRemaining(Consumer userAction) { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/list/ListSpliteratorStub.java b/approximations/src/main/java/stub/java/util/list/ListSpliteratorStub.java new file mode 100644 index 00000000..d7cec2cb --- /dev/null +++ b/approximations/src/main/java/stub/java/util/list/ListSpliteratorStub.java @@ -0,0 +1,60 @@ +package stub.java.util.list; + +import generated.java.util.list.AbstractListImpl; + +import java.lang.LinkageError; +import java.util.Spliterators; +import java.util.function.Consumer; + +public class ListSpliteratorStub extends Spliterators.AbstractSpliterator { + + @SuppressWarnings("unused") + protected ListSpliteratorStub(AbstractListImpl list, int index, int fence, int expectedModCount) { + super(fence - index, expectedModCount); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public ListSpliteratorStub(AbstractListImpl list) { + this(list, 0, -1, 0); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + protected ListSpliteratorStub _create(int index, int fence) { + throw new LinkageError(); + } + + protected int _parentModCount() { + throw new LinkageError(); + } + + @SuppressWarnings("unused") + protected int _storageSize() { + throw new LinkageError(); + } + + public int characteristics() { + throw new LinkageError(); + } + + public long estimateSize() { + throw new LinkageError(); + } + + public void forEachRemaining(Consumer _action) { + throw new LinkageError(); + } + + public long getExactSizeIfKnown() { + throw new LinkageError(); + } + + public boolean tryAdvance(Consumer _action) { + throw new LinkageError(); + } + + public ListSpliteratorStub trySplit() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/list/SubList.java b/approximations/src/main/java/stub/java/util/list/SubList.java new file mode 100644 index 00000000..cef9261f --- /dev/null +++ b/approximations/src/main/java/stub/java/util/list/SubList.java @@ -0,0 +1,207 @@ +package stub.java.util.list; + +import generated.java.util.list.AbstractListImpl; +import generated.java.util.list.SubListImpl; +import org.jetbrains.annotations.NotNull; + +import java.io.Serial; +import java.io.Serializable; +import java.lang.LinkageError; +import java.lang.Object; +import java.lang.String; +import java.util.AbstractList; +import java.util.Collection; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.RandomAccess; +import java.util.Spliterator; +import java.util.function.Consumer; +import java.util.function.IntFunction; +import java.util.function.Predicate; +import java.util.function.UnaryOperator; +import java.util.stream.Stream; + +public final class SubList extends AbstractList implements RandomAccess, Cloneable, Serializable { + + @Serial + private static final long serialVersionUID = 8683452581122892189L; + + @SuppressWarnings("unused") + private SubList(AbstractListImpl list, SubListImpl parent, int offset, int length, int modCount) { + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public SubList(AbstractListImpl list, int fromIndex, int toIndex) { + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public AbstractListImpl _getList() { + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public int _endIndex() { + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public boolean _addAllElements(int index, Collection c) { + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public void _updateSizeAndModCount(int sizeChange) { + throw new LinkageError(); + } + + @SuppressWarnings({"unused", "ProtectedMemberInFinalClass"}) + protected Object[] _mapToArray() { + throw new LinkageError(); + } + + public void add(int index, E element) { + throw new LinkageError(); + } + + public boolean add(E e) { + throw new LinkageError(); + } + + public boolean addAll(@NotNull Collection c) { + throw new LinkageError(); + } + + public boolean addAll(int index, @NotNull Collection c) { + throw new LinkageError(); + } + + public void clear() { + throw new LinkageError(); + } + + public Object clone() throws CloneNotSupportedException { + throw new LinkageError(); + } + + public boolean contains(Object o) { + throw new LinkageError(); + } + + public boolean containsAll(@NotNull Collection c) { + throw new LinkageError(); + } + + public boolean equals(Object o) { + throw new LinkageError(); + } + + public void forEach(Consumer _action) { + throw new LinkageError(); + } + + public E get(int index) { + throw new LinkageError(); + } + + public int hashCode() { + throw new LinkageError(); + } + + public int indexOf(Object o) { + throw new LinkageError(); + } + + public boolean isEmpty() { + throw new LinkageError(); + } + + @NotNull + public Iterator iterator() { + throw new LinkageError(); + } + + public int lastIndexOf(Object o) { + throw new LinkageError(); + } + + @NotNull + public ListIterator listIterator() { + throw new LinkageError(); + } + + @NotNull + public ListIterator listIterator(int index) { + throw new LinkageError(); + } + + public Stream parallelStream() { + throw new LinkageError(); + } + + public boolean remove(Object o) { + throw new LinkageError(); + } + + public E remove(int index) { + throw new LinkageError(); + } + + public boolean removeAll(@NotNull Collection c) { + throw new LinkageError(); + } + + public boolean removeIf(Predicate filter) { + throw new LinkageError(); + } + + public void replaceAll(UnaryOperator operator) { + throw new LinkageError(); + } + + public boolean retainAll(@NotNull Collection c) { + throw new LinkageError(); + } + + public int size() { + throw new LinkageError(); + } + + public void sort(Comparator c) { + throw new LinkageError(); + } + + public Spliterator spliterator() { + throw new LinkageError(); + } + + public Stream stream() { + throw new LinkageError(); + } + + @NotNull + public List subList(int fromIndex, int toIndex) { + throw new LinkageError(); + } + + @NotNull + public Object[] toArray() { + throw new LinkageError(); + } + + public T[] toArray(IntFunction generator) { + throw new LinkageError(); + } + + @NotNull + public T[] toArray(@NotNull T[] array) { + throw new LinkageError(); + } + + public String toString() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/list/SubListIteratorStub.java b/approximations/src/main/java/stub/java/util/list/SubListIteratorStub.java new file mode 100644 index 00000000..a16879ab --- /dev/null +++ b/approximations/src/main/java/stub/java/util/list/SubListIteratorStub.java @@ -0,0 +1,91 @@ +package stub.java.util.list; + +import generated.java.util.list.AbstractListImpl; +import generated.java.util.list.SubListImpl; +import org.usvm.api.SymbolicList; + +import java.lang.LinkageError; +import java.util.function.Consumer; + +public final class SubListIteratorStub extends ListIteratorStub { + + @SuppressWarnings("unused") + public SubListIteratorStub( + AbstractListImpl list, + SubListImpl subList, + int cursor, + int expectedModCount, + int offset, + int length + ) { + super(list); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public SubListIteratorStub(SubListImpl subList, int index) { + super(subList, index); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public SubListIteratorStub(SubListImpl subList) { + super(subList); + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + protected int _getSize(SymbolicList storage) { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public boolean hasPrevious() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public int nextIndex() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public int previousIndex() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public boolean hasNext() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public E next() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public E previous() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public void remove() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public void set(E e) { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public void add(E e) { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public void forEachRemaining(Consumer userAction) { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/list/SubListSpliteratorStub.java b/approximations/src/main/java/stub/java/util/list/SubListSpliteratorStub.java new file mode 100644 index 00000000..8fafac04 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/list/SubListSpliteratorStub.java @@ -0,0 +1,76 @@ +package stub.java.util.list; + +import generated.java.util.list.AbstractListImpl; +import generated.java.util.list.SubListImpl; + +import java.lang.LinkageError; +import java.util.function.Consumer; + +public final class SubListSpliteratorStub extends ListSpliteratorStub { + + @SuppressWarnings("unused") + public SubListSpliteratorStub( + AbstractListImpl list, + SubListImpl subList, + int index, + int fence, + int expectedModCount + ) { + super(list, index, fence, expectedModCount); + throw new LinkageError(); + } + + public SubListSpliteratorStub(SubListImpl subList, int index) { + this(subList._getList(), subList, index, -1, 0); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public SubListSpliteratorStub(SubListImpl subList) { + this(subList, 0); + throw new LinkageError(); + } + + protected SubListSpliteratorStub _create(int index, int fence) { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + protected int _parentModCount() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + protected int _storageSize() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public int characteristics() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public long estimateSize() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public void forEachRemaining(Consumer _action) { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public long getExactSizeIfKnown() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public boolean tryAdvance(Consumer _action) { + throw new LinkageError(); + } + + public SubListSpliteratorStub trySplit() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/map/AbstractMap_Entry.java b/approximations/src/main/java/stub/java/util/map/AbstractMap_Entry.java new file mode 100644 index 00000000..f166fa04 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/map/AbstractMap_Entry.java @@ -0,0 +1,40 @@ +package stub.java.util.map; + +import java.util.Map; + +public class AbstractMap_Entry implements Map.Entry { + + @SuppressWarnings("unused") + public AbstractMap_Entry(Map.Entry entry) { + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public AbstractMap_Entry(K key, V value) { + throw new LinkageError(); + } + + public boolean equals(Object other) { + throw new LinkageError(); + } + + public K getKey() { + throw new LinkageError(); + } + + public V getValue() { + throw new LinkageError(); + } + + public int hashCode() { + throw new LinkageError(); + } + + public V setValue(V value) { + throw new LinkageError(); + } + + public String toString() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/map/Map_Contents.java b/approximations/src/main/java/stub/java/util/map/Map_Contents.java new file mode 100644 index 00000000..e59fe8b9 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/map/Map_Contents.java @@ -0,0 +1,123 @@ +package stub.java.util.map; + +import generated.java.util.map.AbstractMapImpl; +import org.jetbrains.annotations.NotNull; +import runtime.LibSLRuntime; + +import java.util.*; +import java.util.function.Consumer; +import java.util.function.IntFunction; +import java.util.function.Predicate; +import java.util.stream.Stream; + +public abstract class Map_Contents extends AbstractCollection { + + public Map_Contents(AbstractMapImpl map) { + throw new LinkageError(); + } + + LibSLRuntime.Map> getStorage() { + throw new LinkageError(); + } + + abstract Content _contentByKey(LibSLRuntime.Map> storage, K key); + + protected Object[] _mapToArray() { + throw new LinkageError(); + } + + public boolean add(Content e) { + throw new LinkageError(); + } + + public boolean addAll(@NotNull Collection c) { + throw new LinkageError(); + } + + public void clear() { + throw new LinkageError(); + } + + abstract boolean _containsInStorage(LibSLRuntime.Map> storage, Object o); + + public boolean contains(Object obj) { + throw new LinkageError(); + } + + public boolean containsAll(@NotNull Collection c) { + throw new LinkageError(); + } + + Collection _equalsTypeCheck(Object other) { + throw new LinkageError(); + } + + public boolean equals(Object other) { + throw new LinkageError(); + } + + public void forEach(Consumer userAction) { + throw new LinkageError(); + } + + public int hashCode() { + throw new LinkageError(); + } + + public boolean isEmpty() { + throw new LinkageError(); + } + + @NotNull + public Iterator iterator() { + throw new LinkageError(); + } + + public Stream parallelStream() { + throw new LinkageError(); + } + + public abstract boolean remove(Object o); + + public boolean removeAll(@NotNull Collection c) { + throw new LinkageError(); + } + + public boolean removeIf(Predicate filter) { + throw new LinkageError(); + } + + public boolean retainAll(@NotNull Collection c) { + throw new LinkageError(); + } + + public int size() { + throw new LinkageError(); + } + + public Spliterator spliterator() { + throw new LinkageError(); + } + + public Stream stream() { + throw new LinkageError(); + } + + @NotNull + public Object[] toArray() { + throw new LinkageError(); + } + + public T[] toArray(IntFunction generator) { + throw new LinkageError(); + } + + @NotNull + public T[] toArray(@NotNull T[] array) { + throw new LinkageError(); + } + + public String toString() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/map/Map_ContentsSet.java b/approximations/src/main/java/stub/java/util/map/Map_ContentsSet.java new file mode 100644 index 00000000..11ec514a --- /dev/null +++ b/approximations/src/main/java/stub/java/util/map/Map_ContentsSet.java @@ -0,0 +1,110 @@ +package stub.java.util.map; + +import generated.java.util.map.AbstractMapImpl; +import org.jetbrains.annotations.NotNull; + +import java.util.*; +import java.util.function.Consumer; +import java.util.function.IntFunction; +import java.util.function.Predicate; +import java.util.stream.Stream; + +@SuppressWarnings("RedundantMethodOverride") +public abstract class Map_ContentsSet extends Map_Contents implements Set { + + public Map_ContentsSet(AbstractMapImpl map) { + super(map); + throw new LinkageError(); + } + + public boolean add(Content e) { + throw new LinkageError(); + } + + public boolean addAll(@NotNull Collection c) { + throw new LinkageError(); + } + + public void clear() { + throw new LinkageError(); + } + + public boolean contains(Object obj) { + throw new LinkageError(); + } + + public boolean containsAll(@NotNull Collection c) { + throw new LinkageError(); + } + + Set _equalsTypeCheck(Object other) { + throw new LinkageError(); + } + + public boolean equals(Object other) { + throw new LinkageError(); + } + + public void forEach(Consumer userAction) { + throw new LinkageError(); + } + + public int hashCode() { + throw new LinkageError(); + } + + public boolean isEmpty() { + throw new LinkageError(); + } + + @NotNull + public Iterator iterator() { + throw new LinkageError(); + } + + public Stream parallelStream() { + throw new LinkageError(); + } + + public boolean removeAll(@NotNull Collection c) { + throw new LinkageError(); + } + + public boolean removeIf(Predicate filter) { + throw new LinkageError(); + } + + public boolean retainAll(@NotNull Collection c) { + throw new LinkageError(); + } + + public int size() { + throw new LinkageError(); + } + + public Spliterator spliterator() { + throw new LinkageError(); + } + + public Stream stream() { + throw new LinkageError(); + } + + @NotNull + public Object[] toArray() { + throw new LinkageError(); + } + + public T[] toArray(IntFunction generator) { + throw new LinkageError(); + } + + @NotNull + public T[] toArray(@NotNull T[] array) { + throw new LinkageError(); + } + + public String toString() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/map/Map_ContentsSet_Spliterator.java b/approximations/src/main/java/stub/java/util/map/Map_ContentsSet_Spliterator.java new file mode 100644 index 00000000..73396e05 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/map/Map_ContentsSet_Spliterator.java @@ -0,0 +1,71 @@ +package stub.java.util.map; + +import generated.java.util.map.Map_ContentsSetImpl; +import org.usvm.api.SymbolicList; + +import java.util.function.Consumer; + +@SuppressWarnings("unused") +public class Map_ContentsSet_Spliterator extends Map_Contents_Spliterator { + + private Map_ContentsSet_Spliterator( + Map_ContentsSetImpl set, + SymbolicList seenKeys, + SymbolicList unseenKeys, + int index, + int fence, + int expectedModCount + ) { + super(set, seenKeys, unseenKeys, index, fence, expectedModCount); + throw new LinkageError(); + } + + public Map_ContentsSet_Spliterator(Map_ContentsSetImpl set) { + super(set); + throw new LinkageError(); + } + + Map_ContentsSet_Spliterator _createSpliterator( + SymbolicList seenKeys, + SymbolicList unseenKeys, + int index, + int fence, + int expectedModCount + ) { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + protected int _defaultCharacteristics() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public int characteristics() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public long estimateSize() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public void forEachRemaining(Consumer userAction) { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public long getExactSizeIfKnown() { + throw new LinkageError(); + } + + @SuppressWarnings("RedundantMethodOverride") + public boolean tryAdvance(Consumer userAction) { + throw new LinkageError(); + } + + public Map_ContentsSet_Spliterator trySplit() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/map/Map_Contents_Iterator.java b/approximations/src/main/java/stub/java/util/map/Map_Contents_Iterator.java new file mode 100644 index 00000000..6d5d0f9b --- /dev/null +++ b/approximations/src/main/java/stub/java/util/map/Map_Contents_Iterator.java @@ -0,0 +1,41 @@ +package stub.java.util.map; + +import generated.java.util.map.Map_ContentsSetImpl; +import runtime.LibSLRuntime; +import stub.java.util.AbstractIterator; + +import java.util.Map; +import java.util.function.Consumer; + +public class Map_Contents_Iterator extends AbstractIterator { + + @SuppressWarnings("unused") + public Map_Contents_Iterator( + Map_ContentsSetImpl parent, + LibSLRuntime.Map> unseen, + int expectedModCount + ) { + super(expectedModCount); + throw new LinkageError(); + } + + protected int _parentModCount() { + throw new LinkageError(); + } + + public void forEachRemaining(Consumer userAction) { + throw new LinkageError(); + } + + public boolean hasNext() { + throw new LinkageError(); + } + + public Content next() { + throw new LinkageError(); + } + + public void remove() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/map/Map_Contents_Spliterator.java b/approximations/src/main/java/stub/java/util/map/Map_Contents_Spliterator.java new file mode 100644 index 00000000..95f810a1 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/map/Map_Contents_Spliterator.java @@ -0,0 +1,83 @@ +package stub.java.util.map; + +import generated.java.util.map.Map_ContentsImpl; +import org.usvm.api.Engine; +import org.usvm.api.SymbolicList; + +import java.util.Spliterators; +import java.util.function.Consumer; + +public class Map_Contents_Spliterator extends Spliterators.AbstractSpliterator { + + @SuppressWarnings("unused") + Map_Contents_Spliterator( + Map_ContentsImpl contents, + SymbolicList seenKeys, + SymbolicList unseenKeys, + int index, + int fence, + int expectedModCount + ) { + super(fence - index, expectedModCount); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public Map_Contents_Spliterator(Map_ContentsImpl contents) { + this(contents, Engine.makeSymbolicList(), null, 0, -1, 0); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + protected Spliterators.AbstractSpliterator _create(int index, int fence) { + throw new LinkageError(); + } + + @SuppressWarnings("unused") + Map_Contents_Spliterator _createSpliterator( + SymbolicList seenKeys, + SymbolicList unseenKeys, + int index, + int fence, + int expectedModCount + ) { + throw new LinkageError(); + } + + protected int _parentModCount() { + throw new LinkageError(); + } + + protected int _storageSize() { + throw new LinkageError(); + } + + @SuppressWarnings("unused") + protected int _defaultCharacteristics() { + throw new LinkageError(); + } + + public int characteristics() { + throw new LinkageError(); + } + + public long estimateSize() { + throw new LinkageError(); + } + + public void forEachRemaining(Consumer userAction) { + throw new LinkageError(); + } + + public long getExactSizeIfKnown() { + throw new LinkageError(); + } + + public boolean tryAdvance(Consumer userAction) { + throw new LinkageError(); + } + + public Map_Contents_Spliterator trySplit() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/map/Map_EntrySet.java b/approximations/src/main/java/stub/java/util/map/Map_EntrySet.java new file mode 100644 index 00000000..6633b826 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/map/Map_EntrySet.java @@ -0,0 +1,118 @@ +package stub.java.util.map; + +import generated.java.util.map.AbstractMapImpl; +import org.jetbrains.annotations.NotNull; +import runtime.LibSLRuntime; + +import java.util.*; +import java.util.function.Consumer; +import java.util.function.IntFunction; +import java.util.function.Predicate; +import java.util.stream.Stream; + +@SuppressWarnings("RedundantMethodOverride") +public final class Map_EntrySet extends Map_ContentsSet> { + + public Map_EntrySet(AbstractMapImpl parent) { + super(parent); + } + + Map.Entry _contentByKey(LibSLRuntime.Map> storage, K key) { + throw new LinkageError(); + } + + public boolean add(Map.Entry e) { + throw new LinkageError(); + } + + public boolean addAll(@NotNull Collection> c) { + throw new LinkageError(); + } + + public void clear() { + throw new LinkageError(); + } + + boolean _containsInStorage(LibSLRuntime.Map> storage, Object o) { + throw new LinkageError(); + } + + public boolean contains(Object o) { + throw new LinkageError(); + } + + public boolean containsAll(@NotNull Collection c) { + throw new LinkageError(); + } + + public boolean equals(Object other) { + throw new LinkageError(); + } + + public void forEach(Consumer> userAction) { + throw new LinkageError(); + } + + public int hashCode() { + throw new LinkageError(); + } + + public boolean isEmpty() { + throw new LinkageError(); + } + + @NotNull + public Iterator> iterator() { + throw new LinkageError(); + } + + public Stream> parallelStream() { + throw new LinkageError(); + } + + public boolean remove(Object o) { + throw new LinkageError(); + } + + public boolean removeAll(@NotNull Collection c) { + throw new LinkageError(); + } + + public boolean removeIf(Predicate> filter) { + throw new LinkageError(); + } + + public boolean retainAll(@NotNull Collection c) { + throw new LinkageError(); + } + + public int size() { + throw new LinkageError(); + } + + public Spliterator> spliterator() { + throw new LinkageError(); + } + + public Stream> stream() { + throw new LinkageError(); + } + + @NotNull + public Object[] toArray() { + throw new LinkageError(); + } + + public T[] toArray(IntFunction generator) { + throw new LinkageError(); + } + + @NotNull + public T[] toArray(@NotNull T[] array) { + throw new LinkageError(); + } + + public String toString() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/map/Map_KeySet.java b/approximations/src/main/java/stub/java/util/map/Map_KeySet.java new file mode 100644 index 00000000..3a56d12b --- /dev/null +++ b/approximations/src/main/java/stub/java/util/map/Map_KeySet.java @@ -0,0 +1,122 @@ +package stub.java.util.map; + +import generated.java.util.map.AbstractMapImpl; +import org.jetbrains.annotations.NotNull; +import runtime.LibSLRuntime; + +import java.lang.LinkageError; +import java.lang.Object; +import java.lang.String; +import java.util.*; +import java.util.function.Consumer; +import java.util.function.IntFunction; +import java.util.function.Predicate; +import java.util.stream.Stream; + +@SuppressWarnings("RedundantMethodOverride") +public final class Map_KeySet extends Map_ContentsSet { + + public Map_KeySet(AbstractMapImpl parent) { + super(parent); + throw new LinkageError(); + } + + K _contentByKey(LibSLRuntime.Map> storage, K key) { + throw new LinkageError(); + } + + public boolean add(K e) { + throw new LinkageError(); + } + + public boolean addAll(@NotNull Collection c) { + throw new LinkageError(); + } + + public void clear() { + throw new LinkageError(); + } + + boolean _containsInStorage(LibSLRuntime.Map> storage, Object o) { + throw new LinkageError(); + } + + public boolean contains(Object key) { + throw new LinkageError(); + } + + public boolean containsAll(@NotNull Collection c) { + throw new LinkageError(); + } + + public boolean equals(Object other) { + throw new LinkageError(); + } + + public void forEach(Consumer userAction) { + throw new LinkageError(); + } + + public int hashCode() { + throw new LinkageError(); + } + + public boolean isEmpty() { + throw new LinkageError(); + } + + @NotNull + public Iterator iterator() { + throw new LinkageError(); + } + + public Stream parallelStream() { + throw new LinkageError(); + } + + public boolean remove(Object key) { + throw new LinkageError(); + } + + public boolean removeAll(@NotNull Collection c) { + throw new LinkageError(); + } + + public boolean removeIf(Predicate filter) { + throw new LinkageError(); + } + + public boolean retainAll(@NotNull Collection c) { + throw new LinkageError(); + } + + public int size() { + throw new LinkageError(); + } + + public Spliterator spliterator() { + throw new LinkageError(); + } + + public Stream stream() { + throw new LinkageError(); + } + + @NotNull + public Object[] toArray() { + throw new LinkageError(); + } + + public T[] toArray(IntFunction generator) { + throw new LinkageError(); + } + + @NotNull + public T[] toArray(@NotNull T[] array) { + throw new LinkageError(); + } + + public String toString() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/HashMap_KeySet.java b/approximations/src/main/java/stub/java/util/map/Map_Values.java similarity index 50% rename from approximations/src/main/java/stub/java/util/HashMap_KeySet.java rename to approximations/src/main/java/stub/java/util/map/Map_Values.java index 3e0aa775..49eb2a49 100644 --- a/approximations/src/main/java/stub/java/util/HashMap_KeySet.java +++ b/approximations/src/main/java/stub/java/util/map/Map_Values.java @@ -1,64 +1,56 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/HashMap.lsl:63 -// -package stub.java.util; +package stub.java.util.map; + +import generated.java.util.map.AbstractMapImpl; +import org.jetbrains.annotations.NotNull; +import runtime.LibSLRuntime; import java.lang.LinkageError; import java.lang.Object; import java.lang.String; import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.AbstractSet; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Spliterator; +import java.util.*; import java.util.function.Consumer; import java.util.function.IntFunction; import java.util.function.Predicate; import java.util.stream.Stream; -import runtime.LibSLRuntime; -@SuppressWarnings({"all", "unchecked"}) -public final class HashMap_KeySet extends AbstractSet implements LibSLRuntime.HasAutomaton { - private HashMap_KeySet(Void a, Void b) { - super(); - } +@SuppressWarnings("RedundantMethodOverride") +public class Map_Values extends Map_Contents { - private HashMap_KeySet(HashMap _this) { + public Map_Values(AbstractMapImpl parent) { + super(parent); throw new LinkageError(); } - public boolean add(Object e) { + V _contentByKey(LibSLRuntime.Map> storage, K key) { throw new LinkageError(); } - public boolean addAll(Collection c) { + public boolean add(V e) { throw new LinkageError(); } - public final void clear() { + public boolean addAll(@NotNull Collection c) { throw new LinkageError(); } - public final boolean contains(Object key) { + public void clear() { throw new LinkageError(); } - public boolean containsAll(Collection c) { + boolean _containsInStorage(LibSLRuntime.Map> storage, Object value) { throw new LinkageError(); } - public boolean equals(Object other) { + public boolean contains(Object value) { throw new LinkageError(); } - public final void forEach(Consumer userAction) { + public boolean containsAll(@NotNull Collection c) { throw new LinkageError(); } - public int hashCode() { + public void forEach(Consumer userAction) { throw new LinkageError(); } @@ -66,51 +58,54 @@ public boolean isEmpty() { throw new LinkageError(); } - public final Iterator iterator() { + @NotNull + public Iterator iterator() { throw new LinkageError(); } - public Stream parallelStream() { + public Stream parallelStream() { throw new LinkageError(); } - public final boolean remove(Object key) { + public boolean remove(Object value) { throw new LinkageError(); } - public boolean removeAll(Collection c) { + public boolean removeAll(@NotNull Collection c) { throw new LinkageError(); } - public boolean removeIf(Predicate filter) { + public boolean removeIf(Predicate filter) { throw new LinkageError(); } - public boolean retainAll(Collection c) { + public boolean retainAll(@NotNull Collection c) { throw new LinkageError(); } - public final int size() { + public int size() { throw new LinkageError(); } - public final Spliterator spliterator() { + public Spliterator spliterator() { throw new LinkageError(); } - public Stream stream() { + public Stream stream() { throw new LinkageError(); } + @NotNull public Object[] toArray() { throw new LinkageError(); } - public Object[] toArray(IntFunction generator) { + public T[] toArray(IntFunction generator) { throw new LinkageError(); } - public Object[] toArray(Object[] a) { + @NotNull + public T[] toArray(@NotNull T[] array) { throw new LinkageError(); } diff --git a/approximations/src/main/java/stub/java/util/set/Set_Iterator.java b/approximations/src/main/java/stub/java/util/set/Set_Iterator.java new file mode 100644 index 00000000..07ba9ed7 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/set/Set_Iterator.java @@ -0,0 +1,43 @@ +package stub.java.util.set; + +import generated.java.util.set.AbstractSetImpl; +import runtime.LibSLRuntime; +import stub.java.util.AbstractIterator; + +import java.lang.LinkageError; +import java.lang.Object; +import java.util.function.Consumer; + +public final class Set_Iterator extends AbstractIterator { + + @SuppressWarnings("unused") + public Set_Iterator( + int expectedModCount, + LibSLRuntime.Map unseen, + AbstractSetImpl set, + E currentKey + ) { + super(expectedModCount); + throw new LinkageError(); + } + + protected int _parentModCount() { + throw new LinkageError(); + } + + public void forEachRemaining(Consumer userAction) { + throw new LinkageError(); + } + + public boolean hasNext() { + throw new LinkageError(); + } + + public E next() { + throw new LinkageError(); + } + + public void remove() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/set/Set_Spliterator.java b/approximations/src/main/java/stub/java/util/set/Set_Spliterator.java new file mode 100644 index 00000000..ecf044e6 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/set/Set_Spliterator.java @@ -0,0 +1,72 @@ +package stub.java.util.set; + +import java.lang.LinkageError; +import java.lang.SuppressWarnings; +import java.util.Spliterator; +import java.util.Spliterators; +import java.util.function.Consumer; + +import generated.java.util.AbstractSpliteratorImpl; +import generated.java.util.set.AbstractSetImpl; +import generated.java.util.set.Set_SpliteratorImpl; +import org.usvm.api.SymbolicList; + +public final class Set_Spliterator extends Spliterators.AbstractSpliterator { + + @SuppressWarnings("unused") + Set_Spliterator( + AbstractSetImpl set, + SymbolicList seenKeys, + SymbolicList unseenKeys, + int index, + int fence, + int expectedModCount + ) { + super(fence - index, 0); + throw new LinkageError(); + } + + public Set_Spliterator(AbstractSetImpl set) { + super(0, 0); + throw new LinkageError(); + } + + @SuppressWarnings("ProtectedMemberInFinalClass") + protected AbstractSpliteratorImpl _create(int index, int fence) { + throw new LinkageError(); + } + + @SuppressWarnings("ProtectedMemberInFinalClass") + protected int _parentModCount() { + throw new LinkageError(); + } + + @SuppressWarnings("ProtectedMemberInFinalClass") + protected int _storageSize() { + throw new LinkageError(); + } + + public int characteristics() { + throw new LinkageError(); + } + + public long estimateSize() { + throw new LinkageError(); + } + + public void forEachRemaining(Consumer userAction) { + throw new LinkageError(); + } + + public long getExactSizeIfKnown() { + throw new LinkageError(); + } + + public boolean tryAdvance(Consumer userAction) { + throw new LinkageError(); + } + + public Set_SpliteratorImpl trySplit() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/stream/BaseStreamStub.java b/approximations/src/main/java/stub/java/util/stream/BaseStreamStub.java new file mode 100644 index 00000000..2bae8a33 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/stream/BaseStreamStub.java @@ -0,0 +1,69 @@ +package stub.java.util.stream; + +import org.jetbrains.annotations.NotNull; +import org.usvm.api.SymbolicList; + +@SuppressWarnings("unused") +public abstract class BaseStreamStub { + + public BaseStreamStub( + SymbolicList closeHandlers, + boolean isParallel, + boolean linkedOrConsumed + ) { + throw new LinkageError(); + } + + protected SymbolicList _getCloseHandlers() { + throw new LinkageError(); + } + + protected StreamStub _copyToObjStream(T[] storage) { + throw new LinkageError(); + } + + protected IntStreamStub _copyToIntStream(int[] storage) { + throw new LinkageError(); + } + + protected LongStreamStub _copyToLongStream(long[] storage) { + throw new LinkageError(); + } + + protected DoubleStreamStub _copyToDoubleStream(double[] storage) { + throw new LinkageError(); + } + + public void evaluate() { + throw new LinkageError(); + } + + public boolean isParallel() { + throw new LinkageError(); + } + + @NotNull + public BaseStreamStub sequential() { + throw new LinkageError(); + } + + @NotNull + public BaseStreamStub parallel() { + throw new LinkageError(); + } + + abstract protected int _getLength(); + + public long count() { + throw new LinkageError(); + } + + @NotNull + public BaseStreamStub onClose(@NotNull Runnable closeHandler) { + throw new LinkageError(); + } + + public void close() { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/java/util/stream/DoubleStreamLSLIterator.java b/approximations/src/main/java/stub/java/util/stream/DoubleStreamLSLIterator.java deleted file mode 100644 index 130d39c5..00000000 --- a/approximations/src/main/java/stub/java/util/stream/DoubleStreamLSLIterator.java +++ /dev/null @@ -1,45 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/stream/DoubleStream.lsl:39 -// -package stub.java.util.stream; - -import java.lang.Double; -import java.lang.LinkageError; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.PrimitiveIterator; -import java.util.function.Consumer; -import java.util.function.DoubleConsumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public class DoubleStreamLSLIterator implements LibSLRuntime.HasAutomaton, PrimitiveIterator.OfDouble { - private DoubleStreamLSLIterator(Void a, Void b) { - super(); - } - - public boolean hasNext() { - throw new LinkageError(); - } - - public Double next() { - throw new LinkageError(); - } - - public double nextDouble() { - throw new LinkageError(); - } - - public void remove() { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer userAction) { - throw new LinkageError(); - } - - public void forEachRemaining(DoubleConsumer userAction) { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/stream/DoubleStreamLSL.java b/approximations/src/main/java/stub/java/util/stream/DoubleStreamStub.java similarity index 55% rename from approximations/src/main/java/stub/java/util/stream/DoubleStreamLSL.java rename to approximations/src/main/java/stub/java/util/stream/DoubleStreamStub.java index 5dd85f00..b02a5245 100644 --- a/approximations/src/main/java/stub/java/util/stream/DoubleStreamLSL.java +++ b/approximations/src/main/java/stub/java/util/stream/DoubleStreamStub.java @@ -1,14 +1,7 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/stream/DoubleStream.lsl:26 -// package stub.java.util.stream; import java.lang.LinkageError; -import java.lang.Object; import java.lang.Runnable; -import java.lang.SuppressWarnings; -import java.lang.Void; import java.util.DoubleSummaryStatistics; import java.util.OptionalDouble; import java.util.PrimitiveIterator; @@ -24,58 +17,98 @@ import java.util.function.ObjDoubleConsumer; import java.util.function.Supplier; import java.util.stream.DoubleStream; -import java.util.stream.IntStream; -import java.util.stream.LongStream; import java.util.stream.Stream; -import runtime.LibSLRuntime; -@SuppressWarnings({"all", "unchecked"}) -public class DoubleStreamLSL implements LibSLRuntime.HasAutomaton, DoubleStream { - private DoubleStreamLSL(Void a, Void b) { - super(); +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; +import org.usvm.api.SymbolicList; + +public class DoubleStreamStub extends BaseStreamStub implements DoubleStream { + + @SuppressWarnings("unused") + public DoubleStreamStub( + double[] storage, + SymbolicList closeHandlers, + boolean isParallel, + boolean linkedOrConsumed + ) { + super(closeHandlers, isParallel, linkedOrConsumed); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public DoubleStreamStub(double[] storage, SymbolicList closeHandlers, boolean isParallel) { + super(closeHandlers, isParallel, false); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public DoubleStreamStub(double[] storage, SymbolicList closeHandlers) { + super(closeHandlers, false, false); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public DoubleStreamStub(double[] storage) { + super(Engine.makeSymbolicList(), false, false); + throw new LinkageError(); + } + + protected int _getLength() { + throw new LinkageError(); } - public DoubleStream filter(DoublePredicate predicate) { + @NotNull + public DoubleStreamStub filter(@NotNull DoublePredicate predicate) { throw new LinkageError(); } - public DoubleStream map(DoubleUnaryOperator mapper) { + @NotNull + public DoubleStreamStub map(@NotNull DoubleUnaryOperator mapper) { throw new LinkageError(); } - public Stream mapToObj(DoubleFunction mapper) { + @NotNull + public StreamStub mapToObj(@NotNull DoubleFunction mapper) { throw new LinkageError(); } - public LongStream mapToLong(DoubleToLongFunction mapper) { + @NotNull + public LongStreamStub mapToLong(@NotNull DoubleToLongFunction mapper) { throw new LinkageError(); } - public IntStream mapToInt(DoubleToIntFunction mapper) { + @NotNull + public IntStreamStub mapToInt(@NotNull DoubleToIntFunction mapper) { throw new LinkageError(); } - public DoubleStream flatMap(DoubleFunction mapper) { + public DoubleStream flatMap(@NotNull DoubleFunction mapper) { throw new LinkageError(); } - public DoubleStream sorted() { + @NotNull + public DoubleStreamStub sorted() { throw new LinkageError(); } - public DoubleStream distinct() { + @NotNull + public DoubleStreamStub distinct() { throw new LinkageError(); } - public DoubleStream peek(DoubleConsumer _action) { + @NotNull + public DoubleStreamStub peek(@NotNull DoubleConsumer _action) { throw new LinkageError(); } - public DoubleStream limit(long maxSize) { + @NotNull + public DoubleStreamStub limit(long maxSize) { throw new LinkageError(); } - public DoubleStream skip(long n) { + @NotNull + public DoubleStreamStub skip(long n) { throw new LinkageError(); } @@ -99,7 +132,7 @@ public OptionalDouble reduce(DoubleBinaryOperator accumulator) { throw new LinkageError(); } - public Object collect(Supplier supplier, ObjDoubleConsumer accumulator, BiConsumer combiner) { + public R collect(Supplier supplier, ObjDoubleConsumer accumulator, BiConsumer combiner) { throw new LinkageError(); } @@ -135,10 +168,12 @@ public OptionalDouble findAny() { throw new LinkageError(); } + @NotNull public PrimitiveIterator.OfDouble iterator() { throw new LinkageError(); } + @NotNull public Spliterator.OfDouble spliterator() { throw new LinkageError(); } @@ -147,19 +182,23 @@ public boolean isParallel() { throw new LinkageError(); } - public DoubleStream sequential() { + @NotNull + public DoubleStreamStub sequential() { throw new LinkageError(); } - public DoubleStream parallel() { + @NotNull + public DoubleStreamStub parallel() { throw new LinkageError(); } - public DoubleStream unordered() { + @NotNull + public DoubleStreamStub unordered() { throw new LinkageError(); } - public DoubleStream onClose(Runnable closeHandler) { + @NotNull + public DoubleStreamStub onClose(@NotNull Runnable closeHandler) { throw new LinkageError(); } @@ -167,11 +206,13 @@ public void close() { throw new LinkageError(); } - public DoubleStream dropWhile(DoublePredicate predicate) { + @NotNull + public DoubleStreamStub dropWhile(@NotNull DoublePredicate predicate) { throw new LinkageError(); } - public DoubleStream takeWhile(DoublePredicate predicate) { + @NotNull + public DoubleStreamStub takeWhile(@NotNull DoublePredicate predicate) { throw new LinkageError(); } @@ -187,7 +228,7 @@ public DoubleSummaryStatistics summaryStatistics() { throw new LinkageError(); } - public Stream boxed() { + public Stream boxed() { throw new LinkageError(); } } diff --git a/approximations/src/main/java/stub/java/util/stream/IntStreamLSLIterator.java b/approximations/src/main/java/stub/java/util/stream/IntStreamLSLIterator.java deleted file mode 100644 index 3b0d8e79..00000000 --- a/approximations/src/main/java/stub/java/util/stream/IntStreamLSLIterator.java +++ /dev/null @@ -1,45 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/stream/IntStream.lsl:35 -// -package stub.java.util.stream; - -import java.lang.Integer; -import java.lang.LinkageError; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.PrimitiveIterator; -import java.util.function.Consumer; -import java.util.function.IntConsumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public class IntStreamLSLIterator implements LibSLRuntime.HasAutomaton, PrimitiveIterator.OfInt { - private IntStreamLSLIterator(Void a, Void b) { - super(); - } - - public boolean hasNext() { - throw new LinkageError(); - } - - public Integer next() { - throw new LinkageError(); - } - - public int nextInt() { - throw new LinkageError(); - } - - public void remove() { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer userAction) { - throw new LinkageError(); - } - - public void forEachRemaining(IntConsumer userAction) { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/stream/IntStreamLSL.java b/approximations/src/main/java/stub/java/util/stream/IntStreamStub.java similarity index 55% rename from approximations/src/main/java/stub/java/util/stream/IntStreamLSL.java rename to approximations/src/main/java/stub/java/util/stream/IntStreamStub.java index 0ab69db1..814c41d2 100644 --- a/approximations/src/main/java/stub/java/util/stream/IntStreamLSL.java +++ b/approximations/src/main/java/stub/java/util/stream/IntStreamStub.java @@ -1,14 +1,7 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/stream/IntStream.lsl:26 -// package stub.java.util.stream; import java.lang.LinkageError; -import java.lang.Object; import java.lang.Runnable; -import java.lang.SuppressWarnings; -import java.lang.Void; import java.util.IntSummaryStatistics; import java.util.OptionalDouble; import java.util.OptionalInt; @@ -24,59 +17,100 @@ import java.util.function.IntUnaryOperator; import java.util.function.ObjIntConsumer; import java.util.function.Supplier; -import java.util.stream.DoubleStream; import java.util.stream.IntStream; -import java.util.stream.LongStream; import java.util.stream.Stream; -import runtime.LibSLRuntime; -@SuppressWarnings({"all", "unchecked"}) -public class IntStreamLSL implements LibSLRuntime.HasAutomaton, IntStream { - private IntStreamLSL(Void a, Void b) { - super(); +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; +import org.usvm.api.SymbolicList; + +public class IntStreamStub extends BaseStreamStub implements IntStream { + + @SuppressWarnings("unused") + public IntStreamStub( + int[] storage, + SymbolicList closeHandlers, + boolean isParallel, + boolean linkedOrConsumed + ) { + super(closeHandlers, isParallel, linkedOrConsumed); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public IntStreamStub(int[] storage, SymbolicList closeHandlers, boolean isParallel) { + super(closeHandlers, isParallel, false); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public IntStreamStub(int[] storage, SymbolicList closeHandlers) { + super(closeHandlers, false, false); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public IntStreamStub(int[] storage) { + super(Engine.makeSymbolicList(), false, false); + throw new LinkageError(); + } + + protected int _getLength() { + throw new LinkageError(); } - public IntStream filter(IntPredicate predicate) { + @NotNull + public IntStreamStub filter(@NotNull IntPredicate predicate) { throw new LinkageError(); } - public IntStream map(IntUnaryOperator mapper) { + @NotNull + public IntStreamStub map(@NotNull IntUnaryOperator mapper) { throw new LinkageError(); } - public Stream mapToObj(IntFunction mapper) { + @NotNull + public StreamStub mapToObj(@NotNull IntFunction mapper) { throw new LinkageError(); } - public LongStream mapToLong(IntToLongFunction mapper) { + @NotNull + public LongStreamStub mapToLong(@NotNull IntToLongFunction mapper) { throw new LinkageError(); } - public DoubleStream mapToDouble(IntToDoubleFunction mapper) { + @NotNull + public DoubleStreamStub mapToDouble(@NotNull IntToDoubleFunction mapper) { throw new LinkageError(); } - public IntStream flatMap(IntFunction mapper) { + @NotNull + public IntStream flatMap(@NotNull IntFunction mapper) { throw new LinkageError(); } - public IntStream sorted() { + @NotNull + public IntStreamStub sorted() { throw new LinkageError(); } - public IntStream distinct() { + @NotNull + public IntStreamStub distinct() { throw new LinkageError(); } - public IntStream peek(IntConsumer _action) { + @NotNull + public IntStreamStub peek(@NotNull IntConsumer _action) { throw new LinkageError(); } - public IntStream limit(long maxSize) { + @NotNull + public IntStreamStub limit(long maxSize) { throw new LinkageError(); } - public IntStream skip(long n) { + @NotNull + public IntStreamStub skip(long n) { throw new LinkageError(); } @@ -100,7 +134,7 @@ public OptionalInt reduce(IntBinaryOperator accumulator) { throw new LinkageError(); } - public Object collect(Supplier supplier, ObjIntConsumer accumulator, BiConsumer combiner) { + public R collect(Supplier supplier, ObjIntConsumer accumulator, BiConsumer combiner) { throw new LinkageError(); } @@ -136,10 +170,12 @@ public OptionalInt findAny() { throw new LinkageError(); } + @NotNull public PrimitiveIterator.OfInt iterator() { throw new LinkageError(); } + @NotNull public Spliterator.OfInt spliterator() { throw new LinkageError(); } @@ -148,19 +184,23 @@ public boolean isParallel() { throw new LinkageError(); } - public IntStream sequential() { + @NotNull + public IntStreamStub sequential() { throw new LinkageError(); } - public IntStream parallel() { + @NotNull + public IntStreamStub parallel() { throw new LinkageError(); } - public IntStream unordered() { + @NotNull + public IntStreamStub unordered() { throw new LinkageError(); } - public IntStream onClose(Runnable closeHandler) { + @NotNull + public IntStreamStub onClose(@NotNull Runnable closeHandler) { throw new LinkageError(); } @@ -168,19 +208,21 @@ public void close() { throw new LinkageError(); } - public IntStream dropWhile(IntPredicate predicate) { + @NotNull + public IntStreamStub dropWhile(@NotNull IntPredicate predicate) { throw new LinkageError(); } - public IntStream takeWhile(IntPredicate predicate) { + @NotNull + public IntStreamStub takeWhile(@NotNull IntPredicate predicate) { throw new LinkageError(); } - public LongStream asLongStream() { + public LongStreamStub asLongStream() { throw new LinkageError(); } - public DoubleStream asDoubleStream() { + public DoubleStreamStub asDoubleStream() { throw new LinkageError(); } @@ -196,7 +238,7 @@ public IntSummaryStatistics summaryStatistics() { throw new LinkageError(); } - public Stream boxed() { + public Stream boxed() { throw new LinkageError(); } } diff --git a/approximations/src/main/java/stub/java/util/stream/LongStreamLSLIterator.java b/approximations/src/main/java/stub/java/util/stream/LongStreamLSLIterator.java deleted file mode 100644 index f05ce279..00000000 --- a/approximations/src/main/java/stub/java/util/stream/LongStreamLSLIterator.java +++ /dev/null @@ -1,45 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/stream/LongStream.lsl:35 -// -package stub.java.util.stream; - -import java.lang.LinkageError; -import java.lang.Long; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.PrimitiveIterator; -import java.util.function.Consumer; -import java.util.function.LongConsumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public class LongStreamLSLIterator implements LibSLRuntime.HasAutomaton, PrimitiveIterator.OfLong { - private LongStreamLSLIterator(Void a, Void b) { - super(); - } - - public boolean hasNext() { - throw new LinkageError(); - } - - public Long next() { - throw new LinkageError(); - } - - public long nextLong() { - throw new LinkageError(); - } - - public void remove() { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer userAction) { - throw new LinkageError(); - } - - public void forEachRemaining(LongConsumer userAction) { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/stream/LongStreamLSL.java b/approximations/src/main/java/stub/java/util/stream/LongStreamStub.java similarity index 55% rename from approximations/src/main/java/stub/java/util/stream/LongStreamLSL.java rename to approximations/src/main/java/stub/java/util/stream/LongStreamStub.java index 83146f8a..ea41ae70 100644 --- a/approximations/src/main/java/stub/java/util/stream/LongStreamLSL.java +++ b/approximations/src/main/java/stub/java/util/stream/LongStreamStub.java @@ -1,14 +1,11 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/stream/LongStream.lsl:26 -// package stub.java.util.stream; +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; +import org.usvm.api.SymbolicList; + import java.lang.LinkageError; -import java.lang.Object; import java.lang.Runnable; -import java.lang.SuppressWarnings; -import java.lang.Void; import java.util.LongSummaryStatistics; import java.util.OptionalDouble; import java.util.OptionalLong; @@ -24,59 +21,96 @@ import java.util.function.LongUnaryOperator; import java.util.function.ObjLongConsumer; import java.util.function.Supplier; -import java.util.stream.DoubleStream; -import java.util.stream.IntStream; import java.util.stream.LongStream; import java.util.stream.Stream; -import runtime.LibSLRuntime; -@SuppressWarnings({"all", "unchecked"}) -public class LongStreamLSL implements LibSLRuntime.HasAutomaton, LongStream { - private LongStreamLSL(Void a, Void b) { - super(); +public class LongStreamStub extends BaseStreamStub implements LongStream { + + @SuppressWarnings("unused") + public LongStreamStub( + long[] storage, + SymbolicList closeHandlers, + boolean isParallel, + boolean linkedOrConsumed + ) { + super(closeHandlers, isParallel, linkedOrConsumed); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public LongStreamStub(long[] storage, SymbolicList closeHandlers, boolean isParallel) { + super(closeHandlers, isParallel, false); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public LongStreamStub(long[] storage, SymbolicList closeHandlers) { + super(closeHandlers, false, false); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public LongStreamStub(long[] storage) { + super(Engine.makeSymbolicList(), false, false); + throw new LinkageError(); + } + + protected int _getLength() { + throw new LinkageError(); } - public LongStream filter(LongPredicate predicate) { + @NotNull + public LongStreamStub filter(@NotNull LongPredicate predicate) { throw new LinkageError(); } - public LongStream map(LongUnaryOperator mapper) { + @NotNull + public LongStreamStub map(@NotNull LongUnaryOperator mapper) { throw new LinkageError(); } - public Stream mapToObj(LongFunction mapper) { + @NotNull + public StreamStub mapToObj(@NotNull LongFunction mapper) { throw new LinkageError(); } - public IntStream mapToInt(LongToIntFunction mapper) { + @NotNull + public IntStreamStub mapToInt(@NotNull LongToIntFunction mapper) { throw new LinkageError(); } - public DoubleStream mapToDouble(LongToDoubleFunction mapper) { + @NotNull + public DoubleStreamStub mapToDouble(@NotNull LongToDoubleFunction mapper) { throw new LinkageError(); } - public LongStream flatMap(LongFunction mapper) { + @NotNull + public LongStream flatMap(@NotNull LongFunction mapper) { throw new LinkageError(); } - public LongStream sorted() { + @NotNull + public LongStreamStub sorted() { throw new LinkageError(); } - public LongStream distinct() { + @NotNull + public LongStreamStub distinct() { throw new LinkageError(); } - public LongStream peek(LongConsumer _action) { + @NotNull + public LongStreamStub peek(@NotNull LongConsumer _action) { throw new LinkageError(); } - public LongStream limit(long maxSize) { + @NotNull + public LongStreamStub limit(long maxSize) { throw new LinkageError(); } - public LongStream skip(long n) { + @NotNull + public LongStreamStub skip(long n) { throw new LinkageError(); } @@ -100,7 +134,7 @@ public OptionalLong reduce(LongBinaryOperator accumulator) { throw new LinkageError(); } - public Object collect(Supplier supplier, ObjLongConsumer accumulator, BiConsumer combiner) { + public R collect(Supplier supplier, ObjLongConsumer accumulator, BiConsumer combiner) { throw new LinkageError(); } @@ -136,10 +170,12 @@ public OptionalLong findAny() { throw new LinkageError(); } + @NotNull public PrimitiveIterator.OfLong iterator() { throw new LinkageError(); } + @NotNull public Spliterator.OfLong spliterator() { throw new LinkageError(); } @@ -148,19 +184,23 @@ public boolean isParallel() { throw new LinkageError(); } - public LongStream sequential() { + @NotNull + public LongStreamStub sequential() { throw new LinkageError(); } - public LongStream parallel() { + @NotNull + public LongStreamStub parallel() { throw new LinkageError(); } - public LongStream unordered() { + @NotNull + public LongStreamStub unordered() { throw new LinkageError(); } - public LongStream onClose(Runnable closeHandler) { + @NotNull + public LongStreamStub onClose(@NotNull Runnable closeHandler) { throw new LinkageError(); } @@ -168,15 +208,17 @@ public void close() { throw new LinkageError(); } - public LongStream dropWhile(LongPredicate predicate) { + @NotNull + public LongStreamStub dropWhile(@NotNull LongPredicate predicate) { throw new LinkageError(); } - public LongStream takeWhile(LongPredicate predicate) { + @NotNull + public LongStreamStub takeWhile(@NotNull LongPredicate predicate) { throw new LinkageError(); } - public DoubleStream asDoubleStream() { + public DoubleStreamStub asDoubleStream() { throw new LinkageError(); } @@ -192,7 +234,7 @@ public LongSummaryStatistics summaryStatistics() { throw new LinkageError(); } - public Stream boxed() { + public Stream boxed() { throw new LinkageError(); } } diff --git a/approximations/src/main/java/stub/java/util/stream/StreamLSL.java b/approximations/src/main/java/stub/java/util/stream/StreamLSL.java deleted file mode 100644 index 455b4cea..00000000 --- a/approximations/src/main/java/stub/java/util/stream/StreamLSL.java +++ /dev/null @@ -1,208 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/stream/Stream.lsl:34 -// -package stub.java.util.stream; - -import java.lang.LinkageError; -import java.lang.Object; -import java.lang.Runnable; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Comparator; -import java.util.Iterator; -import java.util.Optional; -import java.util.Spliterator; -import java.util.function.BiConsumer; -import java.util.function.BiFunction; -import java.util.function.BinaryOperator; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.IntFunction; -import java.util.function.Predicate; -import java.util.function.Supplier; -import java.util.function.ToDoubleFunction; -import java.util.function.ToIntFunction; -import java.util.function.ToLongFunction; -import java.util.stream.BaseStream; -import java.util.stream.Collector; -import java.util.stream.DoubleStream; -import java.util.stream.IntStream; -import java.util.stream.LongStream; -import java.util.stream.Stream; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public class StreamLSL implements LibSLRuntime.HasAutomaton, Stream { - private StreamLSL(Void a, Void b) { - super(); - } - - public Stream filter(Predicate predicate) { - throw new LinkageError(); - } - - public Stream map(Function mapper) { - throw new LinkageError(); - } - - public IntStream mapToInt(ToIntFunction mapper) { - throw new LinkageError(); - } - - public LongStream mapToLong(ToLongFunction mapper) { - throw new LinkageError(); - } - - public DoubleStream mapToDouble(ToDoubleFunction mapper) { - throw new LinkageError(); - } - - public Stream flatMap(Function mapper) { - throw new LinkageError(); - } - - public IntStream flatMapToInt(Function mapper) { - throw new LinkageError(); - } - - public LongStream flatMapToLong(Function mapper) { - throw new LinkageError(); - } - - public DoubleStream flatMapToDouble(Function mapper) { - throw new LinkageError(); - } - - public Stream distinct() { - throw new LinkageError(); - } - - public Stream sorted() { - throw new LinkageError(); - } - - public Stream sorted(Comparator comparator) { - throw new LinkageError(); - } - - public Stream peek(Consumer _action) { - throw new LinkageError(); - } - - public Stream limit(long maxSize) { - throw new LinkageError(); - } - - public Stream skip(long n) { - throw new LinkageError(); - } - - public void forEach(Consumer _action) { - throw new LinkageError(); - } - - public void forEachOrdered(Consumer _action) { - throw new LinkageError(); - } - - public Object[] toArray() { - throw new LinkageError(); - } - - public Object[] toArray(IntFunction generator) { - throw new LinkageError(); - } - - public Object reduce(Object identity, BinaryOperator accumulator) { - throw new LinkageError(); - } - - public Optional reduce(BinaryOperator accumulator) { - throw new LinkageError(); - } - - public Object reduce(Object identity, BiFunction accumulator, BinaryOperator combiner) { - throw new LinkageError(); - } - - public Object collect(Supplier supplier, BiConsumer accumulator, BiConsumer combiner) { - throw new LinkageError(); - } - - public Object collect(Collector collector) { - throw new LinkageError(); - } - - public Optional min(Comparator comparator) { - throw new LinkageError(); - } - - public Optional max(Comparator comparator) { - throw new LinkageError(); - } - - public long count() { - throw new LinkageError(); - } - - public boolean anyMatch(Predicate predicate) { - throw new LinkageError(); - } - - public boolean allMatch(Predicate predicate) { - throw new LinkageError(); - } - - public boolean noneMatch(Predicate predicate) { - throw new LinkageError(); - } - - public Optional findFirst() { - throw new LinkageError(); - } - - public Optional findAny() { - throw new LinkageError(); - } - - public Iterator iterator() { - throw new LinkageError(); - } - - public Spliterator spliterator() { - throw new LinkageError(); - } - - public boolean isParallel() { - throw new LinkageError(); - } - - public BaseStream sequential() { - throw new LinkageError(); - } - - public BaseStream parallel() { - throw new LinkageError(); - } - - public BaseStream unordered() { - throw new LinkageError(); - } - - public BaseStream onClose(Runnable arg0) { - throw new LinkageError(); - } - - public void close() { - throw new LinkageError(); - } - - public Stream dropWhile(Predicate predicate) { - throw new LinkageError(); - } - - public Stream takeWhile(Predicate predicate) { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/stream/StreamLSLIterator.java b/approximations/src/main/java/stub/java/util/stream/StreamLSLIterator.java deleted file mode 100644 index f22e89e5..00000000 --- a/approximations/src/main/java/stub/java/util/stream/StreamLSLIterator.java +++ /dev/null @@ -1,36 +0,0 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - java/util/stream/Stream.lsl:43 -// -package stub.java.util.stream; - -import java.lang.LinkageError; -import java.lang.Object; -import java.lang.SuppressWarnings; -import java.lang.Void; -import java.util.Iterator; -import java.util.function.Consumer; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public class StreamLSLIterator implements LibSLRuntime.HasAutomaton, Iterator { - private StreamLSLIterator(Void a, Void b) { - super(); - } - - public boolean hasNext() { - throw new LinkageError(); - } - - public Object next() { - throw new LinkageError(); - } - - public void remove() { - throw new LinkageError(); - } - - public void forEachRemaining(Consumer userAction) { - throw new LinkageError(); - } -} diff --git a/approximations/src/main/java/stub/java/util/stream/StreamStub.java b/approximations/src/main/java/stub/java/util/stream/StreamStub.java new file mode 100644 index 00000000..cc683375 --- /dev/null +++ b/approximations/src/main/java/stub/java/util/stream/StreamStub.java @@ -0,0 +1,252 @@ +package stub.java.util.stream; + +import org.jetbrains.annotations.NotNull; +import org.usvm.api.Engine; +import org.usvm.api.SymbolicList; + +import java.lang.LinkageError; +import java.lang.Object; +import java.lang.Runnable; +import java.util.Comparator; +import java.util.Iterator; +import java.util.Optional; +import java.util.Spliterator; +import java.util.function.BiConsumer; +import java.util.function.BiFunction; +import java.util.function.BinaryOperator; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.IntFunction; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.function.ToDoubleFunction; +import java.util.function.ToIntFunction; +import java.util.function.ToLongFunction; +import java.util.stream.Collector; +import java.util.stream.DoubleStream; +import java.util.stream.IntStream; +import java.util.stream.LongStream; +import java.util.stream.Stream; + +public class StreamStub extends BaseStreamStub implements Stream { + + @SuppressWarnings("unused") + public StreamStub( + E[] storage, + SymbolicList handlers, + boolean isParallel, + boolean linkedOrConsumed + ) { + super(handlers, isParallel, linkedOrConsumed); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public StreamStub(E[] storage, SymbolicList handlers, boolean isParallel) { + super(handlers, isParallel, false); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public StreamStub(E[] storage, boolean isParallel) { + super(Engine.makeSymbolicList(), isParallel, false); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public StreamStub(E[] storage, SymbolicList handlers) { + super(handlers, false, false); + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public StreamStub(E[] storage) { + super(Engine.makeSymbolicList(), false, false); + throw new LinkageError(); + } + + protected int _getLength() { + throw new LinkageError(); + } + + public Stream filter(Predicate predicate) { + throw new LinkageError(); + } + + public Stream map(Function mapper) { + throw new LinkageError(); + } + + public IntStream mapToInt(ToIntFunction mapper) { + throw new LinkageError(); + } + + public LongStream mapToLong(ToLongFunction mapper) { + throw new LinkageError(); + } + + public DoubleStream mapToDouble(ToDoubleFunction mapper) { + throw new LinkageError(); + } + + public Stream flatMap(Function> mapper) { + throw new LinkageError(); + } + + public IntStream flatMapToInt(Function mapper) { + throw new LinkageError(); + } + + public LongStream flatMapToLong(Function mapper) { + throw new LinkageError(); + } + + public DoubleStream flatMapToDouble(Function mapper) { + throw new LinkageError(); + } + + public StreamStub distinct() { + throw new LinkageError(); + } + + public StreamStub sorted() { + throw new LinkageError(); + } + + public StreamStub sorted(Comparator comparator) { + throw new LinkageError(); + } + + public StreamStub peek(Consumer _action) { + throw new LinkageError(); + } + + public StreamStub limit(long maxSize) { + throw new LinkageError(); + } + + public StreamStub skip(long n) { + throw new LinkageError(); + } + + public void forEach(Consumer _action) { + throw new LinkageError(); + } + + public void forEachOrdered(Consumer _action) { + throw new LinkageError(); + } + + @NotNull + public Object[] toArray() { + throw new LinkageError(); + } + + @NotNull + public T[] toArray(IntFunction generator) { + throw new LinkageError(); + } + + public E reduce(E identity, BinaryOperator accumulator) { + throw new LinkageError(); + } + + @NotNull + public Optional reduce(BinaryOperator accumulator) { + throw new LinkageError(); + } + + public T reduce(T identity, BiFunction accumulator, BinaryOperator combiner) { + throw new LinkageError(); + } + + public R collect(Supplier supplier, BiConsumer accumulator, BiConsumer combiner) { + throw new LinkageError(); + } + + public R collect(Collector collector) { + throw new LinkageError(); + } + + @NotNull + public Optional min(Comparator comparator) { + throw new LinkageError(); + } + + @NotNull + public Optional max(Comparator comparator) { + throw new LinkageError(); + } + + public long count() { + throw new LinkageError(); + } + + public boolean anyMatch(Predicate predicate) { + throw new LinkageError(); + } + + public boolean allMatch(Predicate predicate) { + throw new LinkageError(); + } + + public boolean noneMatch(Predicate predicate) { + throw new LinkageError(); + } + + @NotNull + public Optional findFirst() { + throw new LinkageError(); + } + + @NotNull + public Optional findAny() { + throw new LinkageError(); + } + + @NotNull + public Iterator iterator() { + throw new LinkageError(); + } + + @NotNull + public Spliterator spliterator() { + throw new LinkageError(); + } + + public boolean isParallel() { + throw new LinkageError(); + } + + @NotNull + public StreamStub sequential() { + throw new LinkageError(); + } + + @NotNull + public StreamStub parallel() { + throw new LinkageError(); + } + + @NotNull + public StreamStub unordered() { + throw new LinkageError(); + } + + @NotNull + public StreamStub onClose(@NotNull Runnable handler) { + throw new LinkageError(); + } + + public void close() { + throw new LinkageError(); + } + + public StreamStub dropWhile(Predicate predicate) { + throw new LinkageError(); + } + + public StreamStub takeWhile(Predicate predicate) { + throw new LinkageError(); + } +} diff --git a/approximations/src/main/java/stub/libsl/utils/SymbolicInputStream.java b/approximations/src/main/java/stub/libsl/utils/SymbolicInputStream.java index 9737515c..4da755cb 100644 --- a/approximations/src/main/java/stub/libsl/utils/SymbolicInputStream.java +++ b/approximations/src/main/java/stub/libsl/utils/SymbolicInputStream.java @@ -1,20 +1,31 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - libsl/utils/SymbolicInputStream.lsl:15 -// package stub.libsl.utils; +import org.jetbrains.annotations.NotNull; + import java.io.InputStream; import java.io.OutputStream; import java.lang.LinkageError; -import java.lang.SuppressWarnings; -import java.lang.Void; -import runtime.LibSLRuntime; - -@SuppressWarnings({"all", "unchecked"}) -public final class SymbolicInputStream extends InputStream implements LibSLRuntime.HasAutomaton { - private SymbolicInputStream(Void a, Void b) { - super(); + +@SuppressWarnings("RedundantThrows") +public final class SymbolicInputStream extends InputStream { + + @SuppressWarnings("unused") + public SymbolicInputStream( + int maxSize, + boolean supportMarks, + int dataSize, + byte[] data, + boolean closed, + int pos, + int markPos, + int markLimit8 + ) { + throw new LinkageError(); + } + + @SuppressWarnings("unused") + public static void _checkFromIndexSize(int fromIndex, int size, int length) { + throw new LinkageError(); } public int available() throws java.io.IOException { @@ -25,7 +36,7 @@ public void close() throws java.io.IOException { throw new LinkageError(); } - public void mark(int readlimit) { + public void mark(int readLimit) { throw new LinkageError(); } @@ -37,11 +48,11 @@ public int read() throws java.io.IOException { throw new LinkageError(); } - public int read(byte[] b) throws java.io.IOException { + public int read(@NotNull byte[] b) throws java.io.IOException { throw new LinkageError(); } - public int read(byte[] b, int off, int len) throws java.io.IOException { + public int read(@NotNull byte[] b, int off, int len) throws java.io.IOException { throw new LinkageError(); } diff --git a/approximations/src/main/java/stub/libsl/utils/VoidInputStream.java b/approximations/src/main/java/stub/libsl/utils/VoidInputStream.java index 20bbf305..e8e139da 100644 --- a/approximations/src/main/java/stub/libsl/utils/VoidInputStream.java +++ b/approximations/src/main/java/stub/libsl/utils/VoidInputStream.java @@ -1,20 +1,18 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - libsl/utils/VoidInputStream.lsl:15 -// package stub.libsl.utils; +import org.jetbrains.annotations.NotNull; + import java.io.InputStream; import java.io.OutputStream; import java.lang.LinkageError; import java.lang.SuppressWarnings; -import java.lang.Void; -import runtime.LibSLRuntime; -@SuppressWarnings({"all", "unchecked"}) -public final class VoidInputStream extends InputStream implements LibSLRuntime.HasAutomaton { - private VoidInputStream(Void a, Void b) { - super(); +@SuppressWarnings("RedundantThrows") +public final class VoidInputStream extends InputStream { + + @SuppressWarnings("unused") + public VoidInputStream(boolean p1) { + throw new LinkageError(); } public int available() throws java.io.IOException { @@ -25,7 +23,7 @@ public void close() throws java.io.IOException { throw new LinkageError(); } - public synchronized void mark(int readlimit) { + public synchronized void mark(int readLimit) { throw new LinkageError(); } @@ -37,11 +35,11 @@ public int read() throws java.io.IOException { throw new LinkageError(); } - public int read(byte[] b) throws java.io.IOException { + public int read(@NotNull byte[] b) throws java.io.IOException { throw new LinkageError(); } - public int read(byte[] b, int off, int len) throws java.io.IOException { + public int read(@NotNull byte[] b, int off, int len) throws java.io.IOException { throw new LinkageError(); } diff --git a/approximations/src/main/java/stub/libsl/utils/VoidOutputStream.java b/approximations/src/main/java/stub/libsl/utils/VoidOutputStream.java index b0663416..ac85ebc0 100644 --- a/approximations/src/main/java/stub/libsl/utils/VoidOutputStream.java +++ b/approximations/src/main/java/stub/libsl/utils/VoidOutputStream.java @@ -1,19 +1,17 @@ -// Generated by the LibSL translator. DO NOT EDIT! -// sources: -// - libsl/utils/VoidOutputStream.lsl:15 -// package stub.libsl.utils; +import org.jetbrains.annotations.NotNull; + import java.io.OutputStream; import java.lang.LinkageError; import java.lang.SuppressWarnings; -import java.lang.Void; -import runtime.LibSLRuntime; -@SuppressWarnings({"all", "unchecked"}) -public final class VoidOutputStream extends OutputStream implements LibSLRuntime.HasAutomaton { - private VoidOutputStream(Void a, Void b) { - super(); +@SuppressWarnings("RedundantThrows") +public final class VoidOutputStream extends OutputStream { + + @SuppressWarnings("unused") + public VoidOutputStream(boolean p1) { + throw new LinkageError(); } public void close() { @@ -24,11 +22,11 @@ public void flush() throws java.io.IOException { throw new LinkageError(); } - public void write(byte[] b) throws java.io.IOException { + public void write(@NotNull byte[] b) throws java.io.IOException { throw new LinkageError(); } - public void write(byte[] b, int off, int len) throws java.io.IOException { + public void write(@NotNull byte[] b, int off, int len) throws java.io.IOException { throw new LinkageError(); } diff --git a/jitpack.yml b/jitpack.yml index f78f664d..bb8a4f69 100644 --- a/jitpack.yml +++ b/jitpack.yml @@ -1 +1 @@ -jdk: openjdk11 \ No newline at end of file +jdk: openjdk17 diff --git a/tests/src/main/java/approximations/java/util/AbstractCollection/ToArrayTest.java b/tests/src/main/java/approximations/java/util/AbstractCollection/ToArrayTest.java new file mode 100644 index 00000000..a0726fa1 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/AbstractCollection/ToArrayTest.java @@ -0,0 +1,188 @@ +package approximations.java.util.AbstractCollection; + +import approximations.Test; + +import java.util.AbstractCollection; +import java.util.Arrays; +import java.util.Iterator; + +@Test +public class ToArrayTest { + static class TestCollection extends AbstractCollection { + private final E[] elements; + private int[] sizes; + private int nextSize; + + public TestCollection(E[] elements) { + this.elements = elements; + setSizeSequence(new int[] { elements.length }); + } + + /* + * Sets the values that size() will return on each use. The next + * call to size will return sizes[0], then sizes[1] etc. This allows us + * to emulate a concurrent change to the contents of the collection + * without having to perform concurrent changes. If sizes[n+1] contains + * a larger value, the collection will appear to have shrunk when + * iterated; if a smaller value then the collection will appear to have + * grown when iterated. + */ + void setSizeSequence(int... sizes) { + this.sizes = sizes; + nextSize = 0; + } + + /* can change collection's size after each invocation */ + @Override + public int size() { + return sizes[nextSize == sizes.length - 1 ? nextSize : nextSize++]; + } + + @Override + public Iterator iterator() { + return new Iterator() { + int pos = 0; + + public boolean hasNext() { + return pos < sizes[nextSize]; + } + public E next() { + return elements[pos++]; + } + public void remove() { + throw new UnsupportedOperationException( + "Not supported yet."); + } + }; + } + } + + static final Object[] OBJECTS = { new Object(), new Object(), new Object() }; + static final TestCollection CANDIDATE = new TestCollection<>(OBJECTS); + static final int CAP = OBJECTS.length; // capacity of the CANDIDATE + static final int LAST = CAP - 1; // last possible array index + Object[] a; + Object[] res; + + int last() { + return a.length - 1; + } + + protected void test() throws Throwable { + // Check array type conversion + res = new TestCollection<>(new Object[] { "1", "2" }).toArray(new String[0]); + check(res instanceof String[]); + check(res.length == 2); + check(res[1] == "2"); + + // Check incompatible type of target array + try { + res = CANDIDATE.toArray(new String[CAP]); + check(false); + } catch (Throwable t) { + check(t instanceof ArrayStoreException); + } + + // Check more elements than a.length + a = new Object[CAP - 1]; // appears too small + res = CANDIDATE.toArray(a); + check(res != a); + check(res[LAST] != null); + + // Check equal elements as a.length + a = new Object[CAP]; // appears to match + res = CANDIDATE.toArray(a); + check(res == a); + check(res[last()] != null); + + // Check equal elements as a.length + a = new Object[CAP + 1]; // appears too big + res = CANDIDATE.toArray(a); + check(res == a); + check(res[last()] == null); + + // Check less elements than expected, but more than a.length + a = new Object[CAP - 2]; // appears too small + CANDIDATE.setSizeSequence(CAP, CAP - 1); + res = CANDIDATE.toArray(a); + check(res != a); + check(res.length == CAP - 1); + check(res[LAST - 1] != null); + + // Check less elements than expected, but equal as a.length + a = Arrays.copyOf(OBJECTS, CAP); // appears to match + CANDIDATE.setSizeSequence(CAP, CAP - 1); + res = CANDIDATE.toArray(a); + check(res == a); + check(res[last()] == null); + + // Check more elements than expected and more than a.length + a = new Object[CAP - 1]; // appears to match + CANDIDATE.setSizeSequence(CAP - 1, CAP); + res = CANDIDATE.toArray(a); + check(res != a); + check(res[LAST] != null); + + // Check more elements than expected, but equal as a.length + a = new Object[CAP - 1]; // appears to match + CANDIDATE.setSizeSequence(CAP - 2, CAP - 1); + res = CANDIDATE.toArray(a); + check(res == a); + check(res[last()] != null); + + // Check more elements than expected, but less than a.length + a = Arrays.copyOf(OBJECTS, CAP); // appears to match + CANDIDATE.setSizeSequence(CAP - 2, CAP - 1); + res = CANDIDATE.toArray(a); + check(res == a); + check(res[last()] == null); + + test_7121314(); + } + + /* + * Major target of this testcase, bug 7121314. + */ + protected void test_7121314() { + // Check equal elements as a.length, but less than expected + a = new Object[CAP - 1]; // appears too small + CANDIDATE.setSizeSequence(CAP, CAP - 1); + res = CANDIDATE.toArray(a); + check(res == a); + check(res[last()] != null); + + // Check less elements than a.length and less than expected + a = Arrays.copyOf(OBJECTS, CAP - 1); // appears too small + CANDIDATE.setSizeSequence(CAP, CAP - 2); + res = CANDIDATE.toArray(a); + check(res == a); + check(res[last()] == null); + + } + + @Test(disabled = true) + public static int test_toArray(int execution) { + ToArrayTest testcase = new ToArrayTest(); + try { + testcase.test(); + } catch (Throwable t) { + unexpected(); + } + if (failed > 0) { + return -1; + } else { + return execution; + } + } + + //--------------------- Infrastructure --------------------------- + static volatile int passed = 0, failed = 0; + static void pass() { passed++; } + static void fail() { failed++; } + static void unexpected() { failed++; } + static void check(boolean cond) { if (cond) pass(); else fail(); } + static void equal(Object x, Object y) { + if (x == null ? y == null : x.equals(y)) pass(); + else { fail(); } + } +} diff --git a/tests/src/main/java/approximations/java/util/AbstractCollection/ToStringTest.java b/tests/src/main/java/approximations/java/util/AbstractCollection/ToStringTest.java new file mode 100644 index 00000000..7fa38e2b --- /dev/null +++ b/tests/src/main/java/approximations/java/util/AbstractCollection/ToStringTest.java @@ -0,0 +1,56 @@ +package approximations.java.util.AbstractCollection; + +import approximations.Test; + +import java.util.*; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.CopyOnWriteArraySet; + +@Test +public class ToStringTest { + private static void realMain() { + testCollection(new LinkedHashSet() { + public int size() { + return super.size() + 1; // Lies, lies, all lies! + }}); + testCollection(new ArrayList<>()); + //testCollection(new Vector<>()); + //testCollection(new CopyOnWriteArrayList<>()); + //testCollection(new CopyOnWriteArraySet<>()); + } + + private static void testCollection(Collection c) { + equal(c.toString(), "[]"); + check(c.add("x")); + equal(c.toString(), "[x]"); + check(c.add("y")); + equal(c.toString(), "[x, y]"); + check(c.add(null)); + equal(c.toString(), "[x, y, null]"); + if (c instanceof AbstractCollection) { + check(c.add(c)); + equal(c.toString(), "[x, y, null, (this Collection)]"); + } + } + + //--------------------- Infrastructure --------------------------- + static volatile int passed = 0, failed = 0; + static void pass() { passed++; } + static void fail() { failed++; } + static void unexpected() { failed++; } + static void check(boolean cond) { if (cond) pass(); else fail(); } + static void equal(Object x, Object y) { + if (x == null ? y == null : x.equals(y)) pass(); + else { fail(); }} + + @Test(disabled = true) + public static int test_toString(int execution) { + try { realMain(); } catch (Throwable t) { unexpected(); } + + if (failed > 0) { + return -1; + } else { + return execution; + } + } +} diff --git a/tests/src/main/java/approximations/java/util/Collection/CollectionDefaults.java b/tests/src/main/java/approximations/java/util/Collection/CollectionDefaults.java new file mode 100644 index 00000000..c38c60b5 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/Collection/CollectionDefaults.java @@ -0,0 +1,203 @@ +package approximations.java.util.Collection; + +import approximations.Test; + +import java.util.*; +import java.util.function.Function; +import java.util.function.Predicate; + +@Test +public class CollectionDefaults { + public static final Predicate pEven = x -> 0 == x % 2; + public static final Predicate pOdd = x -> 1 == x % 2; + + private static final int SIZE = 5; + + private static Function, Collection> getSupplier(int execution) { + // Collection + //ExtendsAbstractCollection::new, + // Lists + //ArrayList::new, + //LinkedList::new, + //ExtendsAbstractList::new, + + // Sets + //HashSet::new, + //LinkedHashSet::new + //ExtendsAbstractSet::new + if (execution == 0) { + return ArrayList::new; + } else if (execution == 1) { + return LinkedList::new; + } else if (execution == 2) { + return HashSet::new; + } else { + return LinkedHashSet::new; + } + } + + public static Set setCases(int execution) { + if (execution == 0) { + return new HashSet<>(); + } else if (execution == 1) { + return new LinkedHashSet<>(); + } else if (execution == 2) { + return new HashSet(){{add(42);}}; + } else { + return new LinkedHashSet(){{add(42);}}; + } + } + + @Test(executionMax = 3) + public static int test_ProvidedWithNull(int execution) { + if (execution < 0 || execution > 3) { + return execution; + } + Set set = setCases(execution); + try { + set.forEach(null); + return -1; + } catch (NullPointerException expected) { // expected + } + try { + set.removeIf(null); + return -1; + } catch (NullPointerException expected) { // expected + } + return execution; + } + + public static List>> prepareTests(Function, Collection> supplier) { + List>> tests = new ArrayList<>(); + List> test1 = new ArrayList<>(); + test1.add(supplier.apply(new ArrayList<>())); + test1.add(supplier.apply(new ArrayList<>())); + tests.add(test1); + //Collection test1 = supplier.apply(new ArrayList<>()); + //Collection test2 = supplier.apply(new ArrayList<>()); + //tests.add(new Collection[] { supplier.apply(new ArrayList<>()), supplier.apply(new ArrayList<>()) }); + //tests.add(new Collection[] { test1, test2 }); + + /*List test21 = new ArrayList<>(), test22 = new ArrayList<>(); + test21.add(42); test22.add(42); + tests.add(new Collection[] { supplier.apply(test21), supplier.apply(test22) }); + + List test31 = new LinkedList<>(), test32 = new LinkedList<>(); + for (int i = 0; i < SIZE; i++) { + test31.add(i); test32.add(i); + } + tests.add(new Collection[] { supplier.apply(test31), supplier.apply(test32) }); + + List test41 = new LinkedList<>(), test42 = new LinkedList<>(); + for (int i = SIZE; i >= 0; i--) { + test41.add(i); test42.add(i); + } + tests.add(new Collection[] { supplier.apply(test41), supplier.apply(test42) }); + + List test51 = new ArrayList<>(), test52 = new LinkedList<>(); + for (int i = 0; i < SIZE; i++) { + test51.add((i * 2) + 1); test52.add((i * 2) + 1); + } + tests.add(new Collection[] { supplier.apply(test51), supplier.apply(test52) }); + + List test61 = new LinkedList<>(), test62 = new ArrayList<>(); + for (int i = 0; i < SIZE; i++) { + test61.add(i * 2); test62.add(i * 2); + } + tests.add(new Collection[] { supplier.apply(test61), supplier.apply(test62) }); + + List test71 = new LinkedList<>(), test72 = new ArrayList<>(); + test71.add(42); test72.add(42); + test71.remove(0); test72.remove(0); + tests.add(new Collection[] { supplier.apply(test71), supplier.apply(test72) }); + + List test81 = new LinkedList<>(), test82 = new ArrayList<>(); + test81.add(42); test82.add(42); + test81.add(43); test82.add(43); + test81.remove(1); test82.remove(1); + tests.add(new Collection[] { supplier.apply(test81), supplier.apply(test82) }); + + List test91 = new ArrayList<>(), test92 = new LinkedList<>(); + for (int i = 0; i < 2 * SIZE; i++) { + test91.add(i); test92.add(i); + } + test91.removeIf(x -> x < SIZE); test92.removeIf(x -> x < SIZE); + tests.add(new Collection[] { supplier.apply(test91), supplier.apply(test92) });*/ + + return tests; + } + + @Test(executionMax = 3) + public static int test_ForEach(int execution) { + if (execution < 0 || execution > 3) { + return execution; + } + final Function, Collection> supplier = getSupplier(execution); + List>> tests = prepareTests(supplier); + for (final List> test : tests) { + final Collection original = test.get(0); //test.expected; + final Collection set = test.get(1); // test.collection; + + try { + set.forEach(null); + return -1; + } catch (NullPointerException expected) { // expected + } + /*if (set instanceof Set && !((set instanceof SortedSet) || (set instanceof LinkedHashSet))) { + CollectionAsserts.assertContentsUnordered(set, original, test.toString()); + } else { + CollectionAsserts.assertContents(set, original, test.toString()); + }*/ + if (!original.equals(set) || !set.equals(original)) { + return -1; + } + } + return execution; + } + + /*@Test(executionMax = 3) + public static int test_RemoveIf(int execution) { + if (execution < 0 || execution > 3) { + return execution; + } + final Function, Collection> supplier = getSupplier(execution); + List[]> tests = prepareTests(supplier); + for (final Collection[] test : tests) { + final Collection original = test[0]; //test.expected; + final Collection set = test[1]; // test.collection; + + try { + set.removeIf(null); + return -1; + } catch (NullPointerException expected) { // expected + } + /*if (set instanceof Set && !((set instanceof SortedSet) || (set instanceof LinkedHashSet))) { + CollectionAsserts.assertContentsUnordered(set, original, test.toString()); + } else { + CollectionAsserts.assertContents(set, original, test.toString()); + }*/ + /*if (!original.equals(set) || !set.equals(original)) { + return -1; + } + + set.removeIf(pEven); + for (int i : set) { + if (i % 2 == 0) { + return -1; + } + } + for (int i : original) { + if (i % 2 == 1) { + if (!set.contains(i)) { + return -1; + } + } + } + set.removeIf(pOdd); + if (!set.isEmpty()) { + return -1; + } + } + return execution; + }*/ +} diff --git a/tests/src/main/java/approximations/java/util/Collection/IteratorAtEndTest.java b/tests/src/main/java/approximations/java/util/Collection/IteratorAtEndTest.java new file mode 100644 index 00000000..e6b1a617 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/Collection/IteratorAtEndTest.java @@ -0,0 +1,142 @@ +package approximations.java.util.Collection; + +import approximations.Test; + +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; + +@Test +public class IteratorAtEndTest { + private static final int SIZE = 6; + + /*static void realMain(String[] args) throws Throwable { + testCollection(new ArrayList()); + testCollection(new LinkedList()); + + testMap(new HashMap()); + testMap(new LinkedHashMap()); + testMap(new ConcurrentHashMap()); + }*/ + + @Test + public static int test_ArrayList(int execution) { + if (testCollection(new ArrayList())) { + return execution; + } else { + return -1; + } + } + + @Test + public static int test_LinkedList(int execution) { + if (testCollection(new LinkedList())) { + return execution; + } else { + return -1; + } + } + + @Test + public static int test_HashMap(int execution) { + if (testMap(new HashMap())) { + return execution; + } else { + return -1; + } + } + + @Test + public static int test_LinkedHashMap(int execution) { + if (testMap(new LinkedHashMap())) { + return execution; + } else { + return -1; + } + } + + @Test + public static int test_ConcurrentHashMap(int execution) { + if (testMap(new ConcurrentHashMap())) { + return execution; + } else { + return -1; + } + } + + static boolean testCollection(Collection c) { + try { + for (int i = 0; i < SIZE; i++) + c.add(i); + return test(c); + } catch (Throwable t) { return false; } + } + + static boolean testMap(Map m) { + try { + for (int i = 0; i < 3*SIZE; i++) + m.put(i, i); + /*test(m.values()); + test(m.keySet()); + test(m.entrySet());*/ + return test(m.values()) & test(m.keySet()) & test(m.entrySet()); + } catch (Throwable t) { return false; } + } + + static boolean test(Collection c) { + try { + final Iterator it = c.iterator(); + /*THROWS(NoSuchElementException.class, + () -> { while (true) it.next(); });*/ + try { + //while (true) it.next(); + for (int i = 0; i < 2 * c.size(); i++) { + it.next(); + } + return false; + } catch (NoSuchElementException e) { + } + try { it.remove(); } + catch (UnsupportedOperationException exc) { return true; } + } catch (Throwable t) { return false; } + + if (c instanceof List) { + final List list = (List) c; + try { + final ListIterator it = list.listIterator(0); + it.next(); + final Object x = it.previous(); + //THROWS(NoSuchElementException.class, () -> it.previous()); + try { + it.previous(); + return false; + } catch (NoSuchElementException e) { + } + try { it.remove(); } + catch (UnsupportedOperationException exc) { return true; } + //check(! list.get(0).equals(x)); + if (list.get(0).equals(x)) { + return false; + } + } catch (Throwable t) { return false; } + + try { + final ListIterator it = list.listIterator(list.size()); + it.previous(); + final Object x = it.next(); + //THROWS(NoSuchElementException.class, () -> it.next()); + try { + it.next(); + return false; + } catch (NoSuchElementException e) { + } + try { it.remove(); } + catch (UnsupportedOperationException exc) { return true; } + //check(! list.get(list.size()-1).equals(x)); + if (list.get(list.size()-1).equals(x)) { + return false; + } + } catch (Throwable t) { return false; } + } + return true; + } +} diff --git a/tests/src/main/java/approximations/java/util/Collection/SetFactoriesTest.java b/tests/src/main/java/approximations/java/util/Collection/SetFactoriesTest.java new file mode 100644 index 00000000..584ad78c --- /dev/null +++ b/tests/src/main/java/approximations/java/util/Collection/SetFactoriesTest.java @@ -0,0 +1,361 @@ +package approximations.java.util.Collection; + +import approximations.Test; + +import java.util.*; + +import static java.util.Arrays.asList; + +//@Test +public class SetFactoriesTest { + /*static final int NUM_STRINGS = 20; // should be larger than the largest fixed-arg overload + static final String[] stringArray; + static { + String[] sa = new String[NUM_STRINGS]; + for (int i = 0; i < NUM_STRINGS; i++) { + sa[i] = String.valueOf((char)('a' + i)); + } + stringArray = sa; + } + + static Object[] a(Set act, Set exp) { + return new Object[] { act, exp }; + } + + static Set hashSetOf(String... args) { + return new HashSet<>(Arrays.asList(args)); + } + + public static Set Set_of(T[] elements) { + return new HashSet<>(asList(elements)); + } + + /*@DataProvider(name="empty") + public Iterator empty() { + return Collections.singletonList( + // actual, expected + a(Set.of(), Collections.emptySet()) + ).iterator(); + }*/ + //static final Object[] empty = a(Set_of(new String[] {}), Collections.emptySet()); + + /*@DataProvider(name="nonempty") + public Iterator nonempty() { + return Arrays.asList( + // actual, expected + a( Set.of("a"), + hashSetOf("a")), + a( Set.of("a", "b"), + hashSetOf("a", "b")), + a( Set.of("a", "b", "c"), + hashSetOf("a", "b", "c")), + a( Set.of("a", "b", "c", "d"), + hashSetOf("a", "b", "c", "d")), + a( Set.of("a", "b", "c", "d", "e"), + hashSetOf("a", "b", "c", "d", "e")), + a( Set.of("a", "b", "c", "d", "e", "f"), + hashSetOf("a", "b", "c", "d", "e", "f")), + a( Set.of("a", "b", "c", "d", "e", "f", "g"), + hashSetOf("a", "b", "c", "d", "e", "f", "g")), + a( Set.of("a", "b", "c", "d", "e", "f", "g", "h"), + hashSetOf("a", "b", "c", "d", "e", "f", "g", "h")), + a( Set.of("a", "b", "c", "d", "e", "f", "g", "h", "i"), + hashSetOf("a", "b", "c", "d", "e", "f", "g", "h", "i")), + a( Set.of("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"), + hashSetOf("a", "b", "c", "d", "e", "f", "g", "h", "i", "j")), + a( Set.of("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"), + Set.of("j", "i", "h", "g", "f", "e", "d", "c", "b", "a")), + a( Set.of(stringArray), + hashSetOf(stringArray)) + ).iterator(); + }*/ + /*static final List nonempty = asList( + a(Set_of(new String[] { "a" }), + hashSetOf("a")), + a(Set_of(new String[] { "a", "b" }), + hashSetOf("a", "b")), + a(Set_of(new String[] { "a", "b", "c" }), + hashSetOf("a", "b", "c")), + a(Set_of(new String[] { "a", "b", "c", "d" }), + hashSetOf("a", "b", "c", "d")), + a(Set_of(new String[] { "a", "b", "c", "d", "e" }), + hashSetOf("a", "b", "c", "d", "e")), + a(Set_of(new String[] { "a", "b", "c", "d", "e", "f" }), + hashSetOf("a", "b", "c", "d", "e", "f")), + a(Set_of(new String[] { "a", "b", "c", "d", "e", "f", "g" }), + hashSetOf("a", "b", "c", "d", "e", "f", "g")), + a(Set_of(new String[] { "a", "b", "c", "d", "e", "f", "g", "h" }), + hashSetOf("a", "b", "c", "d", "e", "f", "g", "h")), + a(Set_of(new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i" }), + hashSetOf("a", "b", "c", "d", "e", "f", "g", "h", "i")), + a(Set_of(new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }), + hashSetOf("a", "b", "c", "d", "e", "f", "g", "h", "i", "j")), + a(Set_of(new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }), + Set_of(new String[] { "j", "i", "h", "g", "f", "e", "d", "c", "b", "a" })), + a(Set_of(stringArray), + hashSetOf(stringArray))); + + /*@DataProvider(name="all") + public Iterator all() { + List all = new ArrayList<>(); + empty().forEachRemaining(all::add); + nonempty().forEachRemaining(all::add); + return all.iterator(); + }*/ + //public static List getAll() { + //List all = new ArrayList<>(); + /*empty().forEachRemaining(all::add); + nonempty().forEachRemaining(all::add); + return all.iterator();*/ + // all.add(empty); + //all.addAll(nonempty); + //return all; + //} + + /*static final List all = getAll(); + + //@Test(dataProvider="all", expectedExceptions=UnsupportedOperationException.class) + @Test(executionMax = 12) + public static int test_cannotAdd(int execution) { + Set act = (Set) all.get(execution)[0]; + try { + act.add("x"); + return -1; + } catch (UnsupportedOperationException e) { + return execution; + } + } + + //@Test(dataProvider="nonempty", expectedExceptions=UnsupportedOperationException.class) + @Test(executionMax = 11) + public static int test_cannotRemove(int execution) { + Set act = (Set) nonempty.get(execution)[0]; + try { + act.remove(act.iterator().next()); + return -1; + } catch (UnsupportedOperationException e) { + return execution; + } + } + + //@Test(dataProvider="all") + @Test(executionMax = 12) + public static int test_contentsMatch(int execution) { + Set act = (Set) nonempty.get(execution)[0]; + Set exp = (Set) nonempty.get(execution)[1]; + //assertEquals(act, exp); + if (!act.equals(exp)) { + return -1; + } else { + return execution; + } + } + + //@Test(expectedExceptions=IllegalArgumentException.class) + @Test + public static int test_dupsDisallowed2(int execution) { + Set set = Set.of("a", "a"); + } + + @Test(expectedExceptions=IllegalArgumentException.class) + public void dupsDisallowed3() { + Set set = Set.of("a", "b", "a"); + } + + @Test(expectedExceptions=IllegalArgumentException.class) + public void dupsDisallowed4() { + Set set = Set.of("a", "b", "c", "a"); + } + + @Test(expectedExceptions=IllegalArgumentException.class) + public void dupsDisallowed5() { + Set set = Set.of("a", "b", "c", "d", "a"); + } + + @Test(expectedExceptions=IllegalArgumentException.class) + public void dupsDisallowed6() { + Set set = Set.of("a", "b", "c", "d", "e", "a"); + } + + @Test(expectedExceptions=IllegalArgumentException.class) + public void dupsDisallowed7() { + Set set = Set.of("a", "b", "c", "d", "e", "f", "a"); + } + + @Test(expectedExceptions=IllegalArgumentException.class) + public void dupsDisallowed8() { + Set set = Set.of("a", "b", "c", "d", "e", "f", "g", "a"); + } + + @Test(expectedExceptions=IllegalArgumentException.class) + public void dupsDisallowed9() { + Set set = Set.of("a", "b", "c", "d", "e", "f", "g", "h", "a"); + } + + @Test(expectedExceptions=IllegalArgumentException.class) + public void dupsDisallowed10() { + Set set = Set.of("a", "b", "c", "d", "e", "f", "g", "h", "i", "a"); + } + + @Test(expectedExceptions=IllegalArgumentException.class) + public void dupsDisallowedN() { + String[] array = stringArray.clone(); + array[0] = array[1]; + Set set = Set.of(array); + } + + @Test(dataProvider="all") + public void hashCodeEqual(Set act, Set exp) { + assertEquals(act.hashCode(), exp.hashCode()); + } + + @Test(dataProvider="all") + public void containsAll(Set act, Set exp) { + assertTrue(act.containsAll(exp)); + assertTrue(exp.containsAll(act)); + } + + @Test(expectedExceptions=NullPointerException.class) + public void nullDisallowed1() { + Set.of((String)null); // force one-arg overload + } + + @Test(expectedExceptions=NullPointerException.class) + public void nullDisallowed2a() { + Set.of("a", null); + } + + @Test(expectedExceptions=NullPointerException.class) + public void nullDisallowed2b() { + Set.of(null, "b"); + } + + @Test(expectedExceptions=NullPointerException.class) + public void nullDisallowed3() { + Set.of("a", "b", null); + } + + @Test(expectedExceptions=NullPointerException.class) + public void nullDisallowed4() { + Set.of("a", "b", "c", null); + } + + @Test(expectedExceptions=NullPointerException.class) + public void nullDisallowed5() { + Set.of("a", "b", "c", "d", null); + } + + @Test(expectedExceptions=NullPointerException.class) + public void nullDisallowed6() { + Set.of("a", "b", "c", "d", "e", null); + } + + @Test(expectedExceptions=NullPointerException.class) + public void nullDisallowed7() { + Set.of("a", "b", "c", "d", "e", "f", null); + } + + @Test(expectedExceptions=NullPointerException.class) + public void nullDisallowed8() { + Set.of("a", "b", "c", "d", "e", "f", "g", null); + } + + @Test(expectedExceptions=NullPointerException.class) + public void nullDisallowed9() { + Set.of("a", "b", "c", "d", "e", "f", "g", "h", null); + } + + @Test(expectedExceptions=NullPointerException.class) + public void nullDisallowed10() { + Set.of("a", "b", "c", "d", "e", "f", "g", "h", "i", null); + } + + @Test(expectedExceptions=NullPointerException.class) + public void nullDisallowedN() { + String[] array = stringArray.clone(); + array[0] = null; + Set.of(array); + } + + @Test(expectedExceptions=NullPointerException.class) + public void nullArrayDisallowed() { + Set.of((Object[])null); + } + + @Test(dataProvider="all", expectedExceptions=NullPointerException.class) + public void containsNullShouldThrowNPE(Set act, Set exp) { + act.contains(null); + } + + @Test(dataProvider="all") + public void serialEquality(Set act, Set exp) { + // assume that act.equals(exp) tested elsewhere + Set copy = serialClone(act); + assertEquals(act, copy); + assertEquals(copy, exp); + } + + @SuppressWarnings("unchecked") + static T serialClone(T obj) { + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(obj); + } + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ObjectInputStream ois = new ObjectInputStream(bais); + return (T) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new AssertionError(e); + } + } + + Set genSet() { + return new HashSet<>(Arrays.asList(1, 2, 3)); + } + + @Test + public void copyOfResultsEqual() { + Set orig = genSet(); + Set copy = Set.copyOf(orig); + + assertEquals(orig, copy); + assertEquals(copy, orig); + } + + @Test + public void copyOfModifiedUnequal() { + Set orig = genSet(); + Set copy = Set.copyOf(orig); + orig.add(4); + + assertNotEquals(orig, copy); + assertNotEquals(copy, orig); + } + + @Test + public void copyOfIdentity() { + Set orig = genSet(); + Set copy1 = Set.copyOf(orig); + Set copy2 = Set.copyOf(copy1); + + assertNotSame(orig, copy1); + assertSame(copy1, copy2); + } + + @Test(expectedExceptions=NullPointerException.class) + public void copyOfRejectsNullCollection() { + Set set = Set.copyOf(null); + } + + @Test(expectedExceptions=NullPointerException.class) + public void copyOfRejectsNullElements() { + Set set = Set.copyOf(Arrays.asList(1, null, 3)); + } + + @Test + public void copyOfAcceptsDuplicates() { + Set set = Set.copyOf(Arrays.asList(1, 1, 2, 3, 3, 3)); + assertEquals(set, Set.of(1, 2, 3)); + }*/ +} diff --git a/tests/src/main/java/approximations/java/util/Random/DistinctSeedsTest.java b/tests/src/main/java/approximations/java/util/Random/DistinctSeedsTest.java new file mode 100644 index 00000000..c1dabff8 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/Random/DistinctSeedsTest.java @@ -0,0 +1,54 @@ +package approximations.java.util.Random; + +import approximations.Test; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Random; + +@Test +public class DistinctSeedsTest { + @Test + public static int test_DistinctSeeds (int execution) throws InterruptedException { + // Strictly speaking, it is possible for these to randomly fail, + // but the probability should be small (approximately 2**-48). + if (new Random().nextLong() == new Random().nextLong() || + new Random().nextLong() == new Random().nextLong()) + throw new RuntimeException("Random() seeds not unique."); + + // Now try generating seeds concurrently + class RandomCollector implements Runnable { + long[] randoms = new long[1<<17]; + public void run() { + for (int i = 0; i < randoms.length; i++) + randoms[i] = new Random().nextLong(); + } + } + final int threadCount = 2; + List collectors = new ArrayList<>(); + List threads = new ArrayList<>(); + for (int i = 0; i < threadCount; i++) { + RandomCollector r = new RandomCollector(); + collectors.add(r); + threads.add(new Thread(r)); + } + for (Thread thread : threads) + thread.start(); + for (Thread thread : threads) + thread.join(); + int collisions = 0; + HashSet s = new HashSet<>(); + for (RandomCollector r : collectors) { + for (long x : r.randoms) { + if (s.contains(x)) + collisions++; + s.add(x); + } + } + if (collisions > 10) { + return -1; + } + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/Random/LXMRandomWithSeedTest.java b/tests/src/main/java/approximations/java/util/Random/LXMRandomWithSeedTest.java new file mode 100644 index 00000000..ef824026 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/Random/LXMRandomWithSeedTest.java @@ -0,0 +1,20 @@ +package approximations.java.util.Random; + +public class LXMRandomWithSeedTest { + /*public static void main(String[] args) { + byte[] seed = new byte[0x100]; + for (int i = 0; i < seed.length; ++i) { + seed[i] = (byte) i; + } + java.util.List> lxmFactories = RandomGeneratorFactory.all() + .filter(factory -> factory.group().equals("LXM")) + .toList(); + for (var lxmFactory : lxmFactories) { + var lxmGen0 = lxmFactory.create(seed); + var lxmGen1 = lxmFactory.create(seed); + if (lxmGen0.nextLong() != lxmGen1.nextLong()) { + throw new RuntimeException("%s(byte[]) is incorrect".formatted(lxmFactory.name())); + } + } + }*/ +} diff --git a/tests/src/main/java/approximations/java/util/Random/NextBytesTest.java b/tests/src/main/java/approximations/java/util/Random/NextBytesTest.java new file mode 100644 index 00000000..3110ac29 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/Random/NextBytesTest.java @@ -0,0 +1,47 @@ +package approximations.java.util.Random; + +import approximations.Test; + +import java.util.Arrays; +import java.util.Random; + +@Test +public class NextBytesTest { + private static void realMain() { + byte[] expected = new byte[] + {27, -105, -24, 83, -77, -29, 119, -74, -106, 68, 54}; + Random r = new java.util.Random(2398579034L); + for (int i = 0; i <= expected.length; i++) { + r.setSeed(2398579034L); + byte[] actual = new byte[i]; + r.nextBytes(actual); + //System.out.println(Arrays.toString(actual)); + check(Arrays.equals(actual, Arrays.copyOf(expected,i))); + } + } + + //--------------------- Infrastructure --------------------------- + static volatile int passed = 0, failed = 0; + static void pass() {passed++;} + static void fail() {failed++; Thread.dumpStack();} + static void fail(String msg) {System.out.println(msg); fail();} + static void unexpected(Throwable t) {failed++; t.printStackTrace();} + static void check(boolean cond) {if (cond) pass(); else fail();} + static void equal(Object x, Object y) { + if (x == null ? y == null : x.equals(y)) pass(); + else fail(x + " not equal to " + y);} + + @Test + public static int test_NextBytes (int execution) { + try { + realMain(); + } catch (Throwable t) { + unexpected(t); + } + if (failed > 0) { + return -1; + } else { + return execution; + } + } +} diff --git a/tests/src/main/java/approximations/java/util/Random/NextIntPowerOfTwoModTest.java b/tests/src/main/java/approximations/java/util/Random/NextIntPowerOfTwoModTest.java new file mode 100644 index 00000000..8eb112b3 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/Random/NextIntPowerOfTwoModTest.java @@ -0,0 +1,19 @@ +package approximations.java.util.Random; + +import approximations.Test; + +import java.util.Random; + +@Test +public class NextIntPowerOfTwoModTest { + @Test + public static int test_NextIntPowerOfTwoMod (int execution) { + Random r = new Random(69); + int total = 0; + for (int i=0; i<1000; i++) + total += r.nextInt(16); + if (total != 7639) + return -1; + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/Random/RandomStreamTest.java b/tests/src/main/java/approximations/java/util/Random/RandomStreamTest.java new file mode 100644 index 00000000..9709f264 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/Random/RandomStreamTest.java @@ -0,0 +1,163 @@ +package approximations.java.util.Random; + +import approximations.Test; + +import java.security.SecureRandom; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Supplier; +import java.util.stream.Stream; + +import static java.util.stream.Collectors.toList; + +@Test +public class RandomStreamTest { + private static final int SIZE = 1000; + + public Object[][] getRandomSuppliers() { + return new Object[][] { + {new Random(), SIZE}, + {new SecureRandom(), SIZE} + }; + } + Object[][] randomSuppliers = getRandomSuppliers(); + + @Test(executionMax = 1) + public int test_RandomIntStream (int execution) { + Random random = (Random) randomSuppliers[execution][0]; + int count = (int) randomSuppliers[execution][1]; + final List destination = new ArrayList<>(count); + random.ints().limit(count).forEach(destination::add); + if (destination.size() != count) { + return -1; + } else { + return execution; + } + } + + @Test(executionMax = 1) + public int test_RandomLongStream (int execution) { + Random random = (Random) randomSuppliers[execution][0]; + int count = (int) randomSuppliers[execution][1]; + final List destination = new ArrayList<>(count); + random.longs().limit(count).forEach(destination::add); + if (destination.size() != count) { + return -1; + } else { + return execution; + } + } + + @Test(executionMax = 1) + public int test_RandomDoubleStream (int execution) { + Random random = (Random) randomSuppliers[execution][0]; + int count = (int) randomSuppliers[execution][1]; + final List destination = new ArrayList<>(count); + random.doubles().limit(count).forEach(destination::add); + + AtomicBoolean failed = new AtomicBoolean(false); + random.doubles().limit(count).forEach(d -> failed.set(!(d >= 0.0 && d < 1.0) && !failed.get())); + + if (destination.size() != count || failed.get()) { + return -1; + } else { + return execution; + } + } + + @Test + public int test_IntStream (int execution) { + final long seed = System.currentTimeMillis(); + final Random r1 = new Random(seed); + final int[] a = new int[SIZE]; + for (int i=0; i < SIZE; i++) { + a[i] = r1.nextInt(); + } + + final Random r2 = new Random(seed); // same seed + final int[] b = r2.ints().limit(SIZE).toArray(); + if (a != b) { + return -1; + } else { + return execution; + } + } + + @Test + public int test_LongStream (int execution) { + final long seed = System.currentTimeMillis(); + final Random r1 = new Random(seed); + final long[] a = new long[SIZE]; + for (int i=0; i < SIZE; i++) { + a[i] = r1.nextLong(); + } + + final Random r2 = new Random(seed); // same seed + final long[] b = r2.longs().limit(SIZE).toArray(); + if (a != b) { + return -1; + } else { + return execution; + } + } + + @Test + public int test_DoubleStream (int execution) { + final long seed = System.currentTimeMillis(); + final Random r1 = new Random(seed); + final double[] a = new double[SIZE]; + for (int i=0; i < SIZE; i++) { + a[i] = r1.nextDouble(); + } + + final Random r2 = new Random(seed); // same seed + final double[] b = r2.doubles().limit(SIZE).toArray(); + if (a != b) { + return -1; + } else { + return execution; + } + } + + @Test + public int test_ThreadLocalIntStream (int execution) throws InterruptedException, ExecutionException, TimeoutException { + ThreadLocalRandom tlr = ThreadLocalRandom.current(); + return testRandomResultSupplierConcurrently(() -> tlr.ints().limit(SIZE).boxed().collect(toList()), execution); + } + + @Test + public int test_ThreadLocalLongStream (int execution) throws InterruptedException, ExecutionException, TimeoutException { + ThreadLocalRandom tlr = ThreadLocalRandom.current(); + return testRandomResultSupplierConcurrently(() -> tlr.longs().limit(SIZE).boxed().collect(toList()), execution); + } + + @Test + public int test_ThreadLocalDoubleStream (int execution) throws InterruptedException, ExecutionException, TimeoutException { + ThreadLocalRandom tlr = ThreadLocalRandom.current(); + return testRandomResultSupplierConcurrently(() -> tlr.doubles().limit(SIZE).boxed().collect(toList()), execution); + } + + int testRandomResultSupplierConcurrently(Supplier s, int execution) throws InterruptedException, ExecutionException, TimeoutException { + // Produce 10 completable future tasks + final int tasks = 10; + List> cfs = Stream.generate(() -> CompletableFuture.supplyAsync(s)). + limit(tasks).collect(toList()); + + // Wait for all tasks to complete + // Timeout is beyond reasonable doubt that completion should + // have occurred unless there is an issue + CompletableFuture all = CompletableFuture.allOf(cfs.stream().toArray(CompletableFuture[]::new)); + all.get(1, TimeUnit.MINUTES); + + // Count the distinct results, which should equal the number of tasks + long rc = cfs.stream().map(CompletableFuture::join).distinct().count(); + if (rc != tasks) { + return -1; + } else { + return execution; + } + } +} diff --git a/tests/src/main/java/approximations/java/util/Spliterator/IteratorFromSpliteratorTest.java b/tests/src/main/java/approximations/java/util/Spliterator/IteratorFromSpliteratorTest.java new file mode 100644 index 00000000..9c7d46d2 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/Spliterator/IteratorFromSpliteratorTest.java @@ -0,0 +1,188 @@ +package approximations.java.util.Spliterator; + +import approximations.Test; + +import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.DoubleConsumer; +import java.util.function.IntConsumer; +import java.util.function.LongConsumer; + +@Test +public class IteratorFromSpliteratorTest { + @Test + public int test_IteratorFromSpliterator (int execution) { + int [] arrayInput = {1, 2, 3, 4, 5}; + List input = new LinkedList(Collections.singleton(arrayInput)); + for (int i = 0; i < input.size(); i++) { + Iterator iterator = Spliterators.iterator(input.spliterator()); + List result = new ArrayList<>(); + int j = i; + while (j++ < input.size() && iterator.hasNext()) { + result.add(iterator.next()); + } + // While SpliteratorTraversingAndSplittingTest tests some scenarios with Spliterators.iterator + // it always wraps the resulting iterator into spliterator again, and this limits the use patterns. + // In particular, calling hasNext() right before forEachRemaining() is not tested. + // Here we cover such a scenario. + if (iterator.hasNext() != (result.size() < input.size())) { + return -1; + } + iterator.forEachRemaining(result::add); + + AtomicBoolean failed = new AtomicBoolean(false); + iterator.forEachRemaining(x -> failed.set(true)); + if (iterator.hasNext()) { + return -1; + } + try { + iterator.next(); + return -1; + } catch (NoSuchElementException e) { + } + iterator.forEachRemaining(x -> failed.set(true)); + if (result != input) { + return -1; + } + if (failed.get()) { + return -1; + } + } + return execution; + } + + @Test + public int test_IteratorFromSpliteratorInt (int execution) { + int[] input = {1, 2, 3, 4, 5}; + for (int i = 0; i < input.length; i++) { + PrimitiveIterator.OfInt iterator = Spliterators.iterator(Arrays.spliterator(input)); + List result = new ArrayList<>(); + int j = i; + while (j++ < input.length && iterator.hasNext()) { + result.add(iterator.nextInt()); + } + if (iterator.hasNext() != (result.size() < input.length)) { + return -1; + } + iterator.forEachRemaining((IntConsumer) result::add); + + AtomicBoolean failed = new AtomicBoolean(false); + iterator.forEachRemaining((IntConsumer) (x -> failed.set(true))); + if (iterator.hasNext()) { + return -1; + } + try { + iterator.next(); + return -1; + } catch (NoSuchElementException e) { + } + iterator.forEachRemaining((IntConsumer) (x -> failed.set(true))); + if (!Arrays.equals(result.stream().mapToInt(x -> x).toArray(), input)) { + return -1; + } + if (failed.get()) { + return -1; + } + } + return execution; + } + + @Test + public int test_IteratorFromSpliteratorLong (int execution) { + long[] input = {1, 2, 3, 4, 5}; + for (int i = 0; i < input.length; i++) { + PrimitiveIterator.OfLong iterator = Spliterators.iterator(Arrays.spliterator(input)); + List result = new ArrayList<>(); + int j = i; + while (j++ < input.length && iterator.hasNext()) { + result.add(iterator.nextLong()); + } + if (iterator.hasNext() != (result.size() < input.length)) { + return -1; + } + iterator.forEachRemaining((LongConsumer) result::add); + + AtomicBoolean failed = new AtomicBoolean(false); + iterator.forEachRemaining((LongConsumer) (x -> failed.set(true))); + if (iterator.hasNext()) { + return -1; + } + try { + iterator.next(); + return -1; + } catch (NoSuchElementException e) { + } + iterator.forEachRemaining((LongConsumer) (x -> failed.set(true))); + if (!Arrays.equals(result.stream().mapToLong(x -> x).toArray(), input)) { + return -1; + } + if (failed.get()) { + return -1; + } + } + return execution; + } + + @Test + public int test_IteratorFromSpliteratorDouble (int execution) { + double[] input = {1, 2, 3, 4, 5}; + for (int i = 0; i < input.length; i++) { + PrimitiveIterator.OfDouble iterator = Spliterators.iterator(Arrays.spliterator(input)); + List result = new ArrayList<>(); + int j = i; + while (j++ < input.length && iterator.hasNext()) { + result.add(iterator.nextDouble()); + } + if (iterator.hasNext() != (result.size() < input.length)) { + return -1; + } + iterator.forEachRemaining((DoubleConsumer) result::add); + + AtomicBoolean failed = new AtomicBoolean(false); + iterator.forEachRemaining((DoubleConsumer) (x -> failed.set(true))); + if (!iterator.hasNext()) { + return -1; + } + try { + iterator.next(); + return -1; + } catch (NoSuchElementException e) { + } + iterator.forEachRemaining((DoubleConsumer) (x -> failed.set(true))); + if (!Arrays.equals(result.stream().mapToDouble(x -> x).toArray(), input)) { + return -1; + } + if (failed.get()) { + return -1; + } + } + return execution; + } + + @Test + public int test_IteratorFromSpliteratorEmpty (int execution) { + Iterator[] iterators = { + Spliterators.iterator(Spliterators.emptySpliterator()), + Spliterators.iterator(Spliterators.emptyIntSpliterator()), + Spliterators.iterator(Spliterators.emptyLongSpliterator()), + Spliterators.iterator(Spliterators.emptyDoubleSpliterator()) + }; + for (Iterator iterator : iterators) { + AtomicBoolean failed = new AtomicBoolean(false); + iterator.forEachRemaining(x -> failed.set(true)); + if (!iterator.hasNext()) { + return -1; + } + iterator.forEachRemaining(x -> failed.set(true)); + try { + iterator.next(); + return -1; + } catch (NoSuchElementException e) { + } + if (failed.get()) { + return -1; + } + } + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/Spliterator/SpliteratorCharacteristicsTest.java b/tests/src/main/java/approximations/java/util/Spliterator/SpliteratorCharacteristicsTest.java new file mode 100644 index 00000000..76818d47 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/Spliterator/SpliteratorCharacteristicsTest.java @@ -0,0 +1,292 @@ +package approximations.java.util.Spliterator; + +import approximations.Test; + +import java.util.*; +import java.util.function.Supplier; +import java.util.stream.DoubleStream; +import java.util.stream.IntStream; +import java.util.stream.LongStream; + +@Test +public class SpliteratorCharacteristicsTest { + /*public void testSpliteratorFromCharSequence() { + class CharSequenceImpl implements CharSequence { + final String s; + + public CharSequenceImpl(String s) { + this.s = s; + } + + @Override + public int length() { + return s.length(); + } + + @Override + public char charAt(int index) { + return s.charAt(index); + } + + @Override + public CharSequence subSequence(int start, int end) { + return s.subSequence(start, end); + } + + @Override + public String toString() { + return s; + } + } + + CharSequence cs = "A"; + Spliterator.OfInt s = cs.chars().spliterator(); + assertCharacteristics(s, Spliterator.IMMUTABLE | Spliterator.ORDERED | + Spliterator.SIZED | Spliterator.SUBSIZED); + assertHasNotCharacteristics(s, Spliterator.CONCURRENT); + s = cs.codePoints().spliterator(); + assertCharacteristics(s, Spliterator.IMMUTABLE | Spliterator.ORDERED); + assertHasNotCharacteristics(s, Spliterator.CONCURRENT); + + for (CharSequence c : Arrays.asList(new CharSequenceImpl("A"), + new StringBuilder("A"), + new StringBuffer("A"))) { + s = cs.chars().spliterator(); + assertCharacteristics(s, Spliterator.ORDERED | + Spliterator.SIZED | Spliterator.SUBSIZED); + assertHasNotCharacteristics(s, Spliterator.CONCURRENT); + s = cs.codePoints().spliterator(); + assertCharacteristics(s, Spliterator.ORDERED); + assertHasNotCharacteristics(s, Spliterator.CONCURRENT); + } + } + + public void testSpliteratorFromCollection() { + List l = Arrays.asList(1, 2, 3, 4); + + { + Spliterator s = Spliterators.spliterator(l, 0); + assertCharacteristics(s, Spliterator.SIZED | Spliterator.SUBSIZED); + assertHasNotCharacteristics(s, Spliterator.CONCURRENT); + } + + { + Spliterator s = Spliterators.spliterator(l, Spliterator.CONCURRENT); + assertHasNotCharacteristics(s, Spliterator.SIZED | Spliterator.SUBSIZED); + assertCharacteristics(s, Spliterator.CONCURRENT); + } + + { + Spliterator s = Spliterators.spliterator(l.iterator(), 1, 0); + assertCharacteristics(s, Spliterator.SIZED | Spliterator.SUBSIZED); + assertHasNotCharacteristics(s, Spliterator.CONCURRENT); + } + + { + Spliterator s = Spliterators.spliterator(l.iterator(), 1, Spliterator.CONCURRENT); + assertHasNotCharacteristics(s, Spliterator.SIZED | Spliterator.SUBSIZED); + assertCharacteristics(s, Spliterator.CONCURRENT); + } + + { + Spliterator s = Spliterators.spliteratorUnknownSize(l.iterator(), 0); + assertHasNotCharacteristics(s, Spliterator.SIZED | Spliterator.SUBSIZED); + } + + { + Spliterator s = Spliterators.spliteratorUnknownSize( + l.iterator(), Spliterator.SIZED | Spliterator.SUBSIZED); + assertHasNotCharacteristics(s, Spliterator.SIZED | Spliterator.SUBSIZED); + } + } + + public void testSpliteratorOfIntFromIterator() { + Supplier si = () -> IntStream.of(1, 2, 3, 4).iterator(); + + { + Spliterator s = Spliterators.spliterator(si.get(), 1, 0); + assertCharacteristics(s, Spliterator.SIZED | Spliterator.SUBSIZED); + assertHasNotCharacteristics(s, Spliterator.CONCURRENT); + } + + { + Spliterator s = Spliterators.spliterator(si.get(), 1, Spliterator.CONCURRENT); + assertHasNotCharacteristics(s, Spliterator.SIZED | Spliterator.SUBSIZED); + assertCharacteristics(s, Spliterator.CONCURRENT); + } + + { + Spliterator s = Spliterators.spliteratorUnknownSize(si.get(), 0); + assertHasNotCharacteristics(s, Spliterator.SIZED | Spliterator.SUBSIZED); + } + + { + Spliterator s = Spliterators.spliteratorUnknownSize( + si.get(), Spliterator.SIZED | Spliterator.SUBSIZED); + assertHasNotCharacteristics(s, Spliterator.SIZED | Spliterator.SUBSIZED); + } + } + + public void testSpliteratorOfLongFromIterator() { + Supplier si = () -> LongStream.of(1, 2, 3, 4).iterator(); + + { + Spliterator s = Spliterators.spliterator(si.get(), 1, 0); + assertCharacteristics(s, Spliterator.SIZED | Spliterator.SUBSIZED); + assertHasNotCharacteristics(s, Spliterator.CONCURRENT); + } + + { + Spliterator s = Spliterators.spliterator(si.get(), 1, Spliterator.CONCURRENT); + assertHasNotCharacteristics(s, Spliterator.SIZED | Spliterator.SUBSIZED); + assertCharacteristics(s, Spliterator.CONCURRENT); + } + + { + Spliterator s = Spliterators.spliteratorUnknownSize(si.get(), 0); + assertHasNotCharacteristics(s, Spliterator.SIZED | Spliterator.SUBSIZED); + } + + { + Spliterator s = Spliterators.spliteratorUnknownSize( + si.get(), Spliterator.SIZED | Spliterator.SUBSIZED); + assertHasNotCharacteristics(s, Spliterator.SIZED | Spliterator.SUBSIZED); + } + } + + public void testSpliteratorOfDoubleFromIterator() { + Supplier si = () -> DoubleStream.of(1, 2, 3, 4).iterator(); + + { + Spliterator s = Spliterators.spliterator(si.get(), 1, 0); + assertCharacteristics(s, Spliterator.SIZED | Spliterator.SUBSIZED); + assertHasNotCharacteristics(s, Spliterator.CONCURRENT); + } + + { + Spliterator s = Spliterators.spliterator(si.get(), 1, Spliterator.CONCURRENT); + assertHasNotCharacteristics(s, Spliterator.SIZED | Spliterator.SUBSIZED); + assertCharacteristics(s, Spliterator.CONCURRENT); + } + + { + Spliterator s = Spliterators.spliteratorUnknownSize(si.get(), 0); + assertHasNotCharacteristics(s, Spliterator.SIZED | Spliterator.SUBSIZED); + } + + { + Spliterator s = Spliterators.spliteratorUnknownSize( + si.get(), Spliterator.SIZED | Spliterator.SUBSIZED); + assertHasNotCharacteristics(s, Spliterator.SIZED | Spliterator.SUBSIZED); + } + } + + // + + public void testHashMap() { + assertMapCharacteristics(new HashMap<>(), + Spliterator.SIZED | Spliterator.DISTINCT); + } + + public void testHashSet() { + assertSetCharacteristics(new HashSet<>(), + Spliterator.SIZED | Spliterator.DISTINCT); + } + + public void testLinkedHashMap() { + assertMapCharacteristics(new LinkedHashMap<>(), + Spliterator.SIZED | Spliterator.DISTINCT | + Spliterator.ORDERED); + } + + public void testLinkedHashSet() { + assertSetCharacteristics(new LinkedHashSet<>(), + Spliterator.SIZED | Spliterator.DISTINCT | + Spliterator.ORDERED); + } + + + // + + + void assertMapCharacteristics(Map m, int keyCharacteristics) { + assertMapCharacteristics(m, keyCharacteristics, 0); + } + + void assertMapCharacteristics(Map m, int keyCharacteristics, int notValueCharacteristics) { + initMap(m); + + assertCharacteristics(m.keySet(), keyCharacteristics); + + assertCharacteristics(m.values(), + keyCharacteristics & ~(Spliterator.DISTINCT | notValueCharacteristics)); + + assertCharacteristics(m.entrySet(), keyCharacteristics); + + if ((keyCharacteristics & Spliterator.SORTED) == 0) { + assertISEComparator(m.keySet()); + assertISEComparator(m.values()); + assertISEComparator(m.entrySet()); + } + } + + void assertSetCharacteristics(Set s, int keyCharacteristics) { + initSet(s); + + assertCharacteristics(s, keyCharacteristics); + + if ((keyCharacteristics & Spliterator.SORTED) == 0) { + assertISEComparator(s); + } + } + + void initMap(Map m) { + m.put(1, "4"); + m.put(2, "3"); + m.put(3, "2"); + m.put(4, "1"); + } + + void initSet(Set s) { + s.addAll(Arrays.asList(1, 2, 3, 4)); + } + + void assertCharacteristics(Collection c, int expectedCharacteristics) { + assertCharacteristics(c.spliterator(), expectedCharacteristics); + } + + void assertCharacteristics(Spliterator s, int expectedCharacteristics) { + assertTrue(s.hasCharacteristics(expectedCharacteristics), + "Spliterator characteristics"); + } + + void assertHasNotCharacteristics(Spliterator s, int expectedCharacteristics) { + assertFalse(s.hasCharacteristics(expectedCharacteristics), + "Spliterator characteristics"); + } + + void assertNullComparator(Collection c) { + assertNull(c.spliterator().getComparator(), + "Comparator of Spliterator of Collection"); + } + + void assertNotNullComparator(Collection c) { + assertNotNull(c.spliterator().getComparator(), + "Comparator of Spliterator of Collection"); + } + + void assertISEComparator(Collection c) { + assertISEComparator(c.spliterator()); + } + + void assertISEComparator(Spliterator s) { + boolean caught = false; + try { + s.getComparator(); + } + catch (IllegalStateException e) { + caught = true; + } + assertTrue(caught, "Throwing IllegalStateException"); + }*/ +} diff --git a/tests/src/main/java/approximations/java/util/Spliterator/SpliteratorCollisionsTest.java b/tests/src/main/java/approximations/java/util/Spliterator/SpliteratorCollisionsTest.java new file mode 100644 index 00000000..d132bb99 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/Spliterator/SpliteratorCollisionsTest.java @@ -0,0 +1,300 @@ +package approximations.java.util.Spliterator; + +import approximations.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Spliterator; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.function.UnaryOperator; + +@Test +public class SpliteratorCollisionsTest { + /*private static final List SIZES = Arrays.asList(0, 1, 10, 100, 1000); + + private static class SpliteratorDataBuilder { + List data; + List exp; + Map mExp; + + SpliteratorDataBuilder(List data, List exp) { + this.data = data; + this.exp = exp; + this.mExp = createMap(exp); + } + + Map createMap(List l) { + Map m = new LinkedHashMap<>(); + for (T t : l) { + m.put(t, t); + } + return m; + } + + void add(String description, Collection expected, Supplier> s) { + description = joiner(description).toString(); + data.add(new Object[]{description, expected, s}); + } + + void add(String description, Supplier> s) { + add(description, exp, s); + } + + void addCollection(Function, ? extends Collection> c) { + add("new " + c.apply(Collections.emptyList()).getClass().getName() + ".spliterator()", + () -> c.apply(exp).spliterator()); + } + + void addList(Function, ? extends List> l) { + // @@@ If collection is instance of List then add sub-list tests + addCollection(l); + } + + void addMap(Function, ? extends Map> m) { + String description = "new " + m.apply(Collections.emptyMap()).getClass().getName(); + add(description + ".keySet().spliterator()", () -> m.apply(mExp).keySet().spliterator()); + add(description + ".values().spliterator()", () -> m.apply(mExp).values().spliterator()); + add(description + ".entrySet().spliterator()", mExp.entrySet(), () -> m.apply(mExp).entrySet().spliterator()); + } + + StringBuilder joiner(String description) { + return new StringBuilder(description). + append(" {"). + append("size=").append(exp.size()). + append("}"); + } + } + + static Object[][] spliteratorDataProvider = getSpliteratorDataProvider(); + + @DataProvider(name = "HashableIntSpliterator") + public static Object[][] getSpliteratorDataProvider() { + List data = new ArrayList<>(); + for (int size : SIZES) { + List exp = listIntRange(size, false); + SpliteratorDataBuilder db = new SpliteratorDataBuilder<>(data, exp); + + // Maps + db.addMap(HashMap::new); + db.addMap(LinkedHashMap::new); + + // Collections that use HashMap + db.addCollection(HashSet::new); + db.addCollection(LinkedHashSet::new); + } + return data.toArray(new Object[0][]); + } + + static Object[][] spliteratorDataProviderWithNull = getSpliteratorNullDataProvider(); + + @DataProvider(name = "HashableIntSpliteratorWithNull") + public static Object[][] getSpliteratorNullDataProvider() { + List data = new ArrayList<>(); + for (int size : SIZES) { + List exp = listIntRange(size, true); + SpliteratorDataBuilder db = new SpliteratorDataBuilder<>(data, exp); + + // Maps + db.addMap(HashMap::new); + db.addMap(LinkedHashMap::new); + // TODO: add this back in if we decide to keep TreeBin in WeakHashMap + //db.addMap(WeakHashMap::new); + + // Collections that use HashMap + db.addCollection(HashSet::new); + db.addCollection(LinkedHashSet::new); +// db.addCollection(TreeSet::new); + + } + return data.toArray(new Object[0][]); + } + + static final class HashableInteger implements Comparable { + + final int value; + final int hashmask; //yes duplication + + HashableInteger(int value, int hashmask) { + this.value = value; + this.hashmask = hashmask; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof HashableInteger) { + HashableInteger other = (HashableInteger) obj; + + return other.value == value; + } + + return false; + } + + @Override + public int hashCode() { + return value % hashmask; + } + + @Override + public int compareTo(HashableInteger o) { + return value - o.value; + } + + @Override + public String toString() { + return Integer.toString(value); + } + } + + private static List listIntRange(int upTo, boolean withNull) { + List exp = new ArrayList<>(); + if (withNull) { + exp.add(null); + } + for (int i = 0; i < upTo; i++) { + exp.add(new HashableInteger(i, 10)); + } + return Collections.unmodifiableList(exp); + } + + @Test + int test_NullPointerException (int execution) { + String description = spliteratorDataProvider[execution][0]; + Collection exp, + Supplier> s + assertThrowsNPE(() -> s.get().forEachRemaining(null)); + assertThrowsNPE(() -> s.get().tryAdvance(null)); + } + + @Test(dataProvider = "HashableIntSpliteratorWithNull") + void testNullPointerExceptionWithNull(String description, + Collection exp, + Supplier> s) { + assertThrowsNPE(() -> s.get().forEachRemaining(null)); + assertThrowsNPE(() -> s.get().tryAdvance(null)); + } + + + @Test(dataProvider = "HashableIntSpliterator") + void testForEach(String description, + Collection exp, + Supplier> s) { + testForEach(exp, s, UnaryOperator.identity()); + } + + @Test(dataProvider = "HashableIntSpliteratorWithNull") + void testForEachWithNull(String description, + Collection exp, + Supplier> s) { + testForEach(exp, s, UnaryOperator.identity()); + } + + + @Test(dataProvider = "HashableIntSpliterator") + void testTryAdvance(String description, + Collection exp, + Supplier> s) { + testTryAdvance(exp, s, UnaryOperator.identity()); + } + + @Test(dataProvider = "HashableIntSpliteratorWithNull") + void testTryAdvanceWithNull(String description, + Collection exp, + Supplier> s) { + testTryAdvance(exp, s, UnaryOperator.identity()); + } + + @Test(dataProvider = "HashableIntSpliterator") + void testMixedTryAdvanceForEach(String description, + Collection exp, + Supplier> s) { + testMixedTryAdvanceForEach(exp, s, UnaryOperator.identity()); + } + + @Test(dataProvider = "HashableIntSpliteratorWithNull") + void testMixedTryAdvanceForEachWithNull(String description, + Collection exp, + Supplier> s) { + testMixedTryAdvanceForEach(exp, s, UnaryOperator.identity()); + } + + @Test(dataProvider = "HashableIntSpliterator") + void testMixedTraverseAndSplit(String description, + Collection exp, + Supplier> s) { + testMixedTraverseAndSplit(exp, s, UnaryOperator.identity()); + } + + @Test(dataProvider = "HashableIntSpliteratorWithNull") + void testMixedTraverseAndSplitWithNull(String description, + Collection exp, + Supplier> s) { + testMixedTraverseAndSplit(exp, s, UnaryOperator.identity()); + } + + @Test(dataProvider = "HashableIntSpliterator") + void testSplitAfterFullTraversal(String description, + Collection exp, + Supplier> s) { + testSplitAfterFullTraversal(s, UnaryOperator.identity()); + } + + @Test(dataProvider = "HashableIntSpliteratorWithNull") + void testSplitAfterFullTraversalWithNull(String description, + Collection exp, + Supplier> s) { + testSplitAfterFullTraversal(s, UnaryOperator.identity()); + } + + + @Test(dataProvider = "HashableIntSpliterator") + void testSplitOnce(String description, + Collection exp, + Supplier> s) { + testSplitOnce(exp, s, UnaryOperator.identity()); + } + + @Test(dataProvider = "HashableIntSpliteratorWithNull") + void testSplitOnceWithNull(String description, + Collection exp, + Supplier> s) { + testSplitOnce(exp, s, UnaryOperator.identity()); + } + + @Test(dataProvider = "HashableIntSpliterator") + void testSplitSixDeep(String description, + Collection exp, + Supplier> s) { + testSplitSixDeep(exp, s, UnaryOperator.identity()); + } + + @Test(dataProvider = "HashableIntSpliteratorWithNull") + void testSplitSixDeepWithNull(String description, + Collection exp, + Supplier> s) { + testSplitSixDeep(exp, s, UnaryOperator.identity()); + } + + @Test(dataProvider = "HashableIntSpliterator") + void testSplitUntilNull(String description, + Collection exp, + Supplier> s) { + testSplitUntilNull(exp, s, UnaryOperator.identity()); + } + + @Test(dataProvider = "HashableIntSpliteratorWithNull") + void testSplitUntilNullWithNull(String description, + Collection exp, + Supplier> s) { + testSplitUntilNull(exp, s, UnaryOperator.identity()); + }*/ +} diff --git a/tests/src/main/java/approximations/java/util/Spliterator/Spliterator_Tests.java b/tests/src/main/java/approximations/java/util/Spliterator/Spliterator_Tests.java new file mode 100644 index 00000000..91a2f781 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/Spliterator/Spliterator_Tests.java @@ -0,0 +1,87 @@ +package approximations.java.util.Spliterator; + +import approximations.Test; +import java.util.Arrays; +import java.util.Spliterators; + +@Test +public class Spliterator_Tests { + @Test + public int test_SpliteratorNPEs(int execution) { + try { + Arrays.spliterator((int[]) null, 0, 0); + Arrays.spliterator((long[]) null, 0, 0); + Arrays.spliterator((double[]) null, 0, 0); + Arrays.spliterator((String[]) null, 0, 0); + } catch (NullPointerException e) { + return execution; + } + return -1; + } + + @Test + public int test_SpliteratorAIOBEs(int execution) { + // origin > fence + try { + Arrays.spliterator(new int[]{}, 1, 0); + Arrays.spliterator(new long[]{}, 1, 0); + Arrays.spliterator(new double[]{}, 1, 0); + Arrays.spliterator(new String[]{}, 1, 0); + + // bad origin + Arrays.spliterator(new int[]{}, -1, 0); + Arrays.spliterator(new long[]{}, -1, 0); + Arrays.spliterator(new double[]{}, -1, 0); + Arrays.spliterator(new String[]{}, -1, 0); + + // bad fence + Arrays.spliterator(new int[]{}, 0, 1); + Arrays.spliterator(new long[]{}, 0, 1); + Arrays.spliterator(new double[]{}, 0, 1); + Arrays.spliterator(new String[]{}, 0, 1); + } catch (ArrayIndexOutOfBoundsException e) { + return execution; + } + return -1; + } + + + @Test + public int test_SpliteratorNPEsFromSpliterators(int execution) { + try { + Spliterators.spliterator((int[]) null, 0, 0, 0); + Spliterators.spliterator((long[]) null, 0, 0, 0); + Spliterators.spliterator((double[]) null, 0, 0, 0); + Spliterators.spliterator((String[]) null, 0, 0, 0); + } catch (NullPointerException e) { + return execution; + } + return -1; + } + + @Test + public int test_SpliteratorAIOBEsFromSpliterators(int execution) { + // origin > fence + try { + Spliterators.spliterator(new int[]{}, 1, 0, 0); + Spliterators.spliterator(new long[]{}, 1, 0, 0); + Spliterators.spliterator(new double[]{}, 1, 0, 0); + Spliterators.spliterator(new String[]{}, 1, 0, 0); + + // bad origin + Spliterators.spliterator(new int[]{}, -1, 0, 0); + Spliterators.spliterator(new long[]{}, -1, 0, 0); + Spliterators.spliterator(new double[]{}, -1, 0, 0); + Spliterators.spliterator(new String[]{}, -1, 0, 0); + + // bad fence + Spliterators.spliterator(new int[]{}, 0, 1, 0); + Spliterators.spliterator(new long[]{}, 0, 1, 0); + Spliterators.spliterator(new double[]{}, 0, 1, 0); + Spliterators.spliterator(new String[]{}, 0, 1, 0); + } catch (ArrayIndexOutOfBoundsException e) { + return execution; + } + return -1; + } +} diff --git a/tests/src/main/java/approximations/java/util/list/AbstractList/CheckForComodificationTest.java b/tests/src/main/java/approximations/java/util/list/AbstractList/CheckForComodificationTest.java new file mode 100644 index 00000000..ae170f9e --- /dev/null +++ b/tests/src/main/java/approximations/java/util/list/AbstractList/CheckForComodificationTest.java @@ -0,0 +1,26 @@ +package approximations.java.util.list.AbstractList; + +import approximations.Test; + +import java.util.ArrayList; +import java.util.ConcurrentModificationException; +import java.util.List; + +@Test +public class CheckForComodificationTest { + private static final int LENGTH = 10; + @Test + public static int test_checkForComodification(int execution) { + List list = new ArrayList<>(); + for (int i = 0; i < LENGTH; i++) + list.add(i); + try { + for (int i : list) + if (i == LENGTH - 3) + list.remove(i); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + } +} diff --git a/tests/src/main/java/approximations/java/util/list/AbstractList/CheckForIndexOutOfBoundsExceptionTest.java b/tests/src/main/java/approximations/java/util/list/AbstractList/CheckForIndexOutOfBoundsExceptionTest.java new file mode 100644 index 00000000..38a28e6f --- /dev/null +++ b/tests/src/main/java/approximations/java/util/list/AbstractList/CheckForIndexOutOfBoundsExceptionTest.java @@ -0,0 +1,68 @@ +package approximations.java.util.list.AbstractList; + +import approximations.Test; + +import java.util.*; + +@Test +public class CheckForIndexOutOfBoundsExceptionTest { + List list = new ArrayList<>(2); + + @Test + public int checkIteratorNext1(int execution) { + List list = new ArrayList<>(2); + list.add("x"); + list.add("x"); + Iterator iterator = list.iterator(); + try { + for (int i = 0; i <= list.size(); i++) { + iterator.next(); + } + return -1; + } catch (NoSuchElementException e) { + return execution; + } + } + + @Test + public int checkIteratorNext2(int execution) { + List list = new ArrayList<>(2); + list.add("x"); + list.add("x"); + Iterator iterator = list.iterator(); + for (int i = 0; i <= list.size(); i++) { + try { + iterator.next(); + } catch (NoSuchElementException e) { + if (i == list.size()) { + return execution; + } else { + return -1; + } + } + } + return -1; + } + + @Test + public int checkListIteratorNext(int execution) { + ListIterator iterator = list.listIterator(list.size()); + try { + iterator.next(); + return -1; + } catch (NoSuchElementException e) { + return execution; + } + } + + @Test + public int checkListIteratorPrevious(int execution) { + ListIterator iterator = list.listIterator(0); + try { + iterator.previous(); + return -1; + } catch (NoSuchElementException e) { + return execution; + } + } +} diff --git a/tests/src/main/java/approximations/java/util/list/AbstractList/FailFastIteratorTest.java b/tests/src/main/java/approximations/java/util/list/AbstractList/FailFastIteratorTest.java new file mode 100644 index 00000000..dc51f37f --- /dev/null +++ b/tests/src/main/java/approximations/java/util/list/AbstractList/FailFastIteratorTest.java @@ -0,0 +1,72 @@ +package approximations.java.util.list.AbstractList; + +import approximations.Test; + +import java.util.ArrayList; +import java.util.ConcurrentModificationException; +import java.util.List; +import java.util.ListIterator; + +@Test +public class FailFastIteratorTest { + @Test + public static int test_failFastIteratorTest(int execution) { + List orig = new ArrayList(5); + for (int i=95; i<100; i++) + orig.add(i); + + List copy = new ArrayList(orig); + if (copy.size() != 5) { + return -1; + } + try { + ListIterator i = orig.listIterator(); + i.next(); + orig.remove(4); + orig.add(99); + i.remove(); + return -1; + } catch (ConcurrentModificationException e) { + } + if (!copy.equals(orig)) + return -1; + + try { + ListIterator i = orig.listIterator(); + i.next(); + orig.remove(4); + orig.add(99); + i.set(666); + return -1; + } catch (ConcurrentModificationException e) { + } + if (!copy.equals(orig)) + return -1; + + try { + ListIterator i = orig.listIterator(); + orig.remove(4); + orig.add(99); + i.add(666); + return -1; + } catch (ConcurrentModificationException e) { + } + if (!copy.equals(orig)) + return -1; + return execution; + } + + @Test + public static int test_listCopy(int execution) { + List orig = new ArrayList(5); + for (int i=95; i<100; i++) + orig.add(i); + + List copy = new ArrayList(orig); + if (copy.get(3) == orig.get(3)) { + return execution; + } else { + return -1; + } + } +} diff --git a/tests/src/main/java/approximations/java/util/list/AbstractList/HasNextAfterExceptionTest.java b/tests/src/main/java/approximations/java/util/list/AbstractList/HasNextAfterExceptionTest.java new file mode 100644 index 00000000..07a552c6 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/list/AbstractList/HasNextAfterExceptionTest.java @@ -0,0 +1,26 @@ +package approximations.java.util.list.AbstractList; + +import approximations.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.ListIterator; +import java.util.NoSuchElementException; + +@Test +public class HasNextAfterExceptionTest { + @Test + public static int test_hasNextAfterExceptionTest(int execution) { + List list = new ArrayList(); + ListIterator i = list.listIterator(); + try { + i.previous(); + } + catch (NoSuchElementException e) { + } + if (i.hasNext()) { + return -1; + } + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/list/ArrayList/AddAllTest.java b/tests/src/main/java/approximations/java/util/list/ArrayList/AddAllTest.java new file mode 100644 index 00000000..6461c499 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/list/ArrayList/AddAllTest.java @@ -0,0 +1,53 @@ +package approximations.java.util.list.ArrayList; + +import approximations.Test; + +import java.util.*; + +@Test +public class AddAllTest { + @Test + public static int test_addAll(int execution) { + for (int j = 0; j < 1; j++) { + Map m = new HashMap(100); + for (int i = 0; i < 100; i++) + m.put(new Object(), Boolean.TRUE); + new ArrayList().addAll(m.keySet()); + } + + for (int j = 0; j < 1; j++) { + Map m = new HashMap(100); + for (int i = 0; i < 100; i++) + m.put(new Object(), Boolean.TRUE); + new LinkedList().addAll(m.keySet()); + } + + for (int j = 0; j < 1; j++) { + Map m = new HashMap(100); + for (int i = 0; i < 100; i++) + m.put(new Object(), Boolean.TRUE); + List list = new ArrayList(); + list.add("inka"); list.add("dinka"); list.add("doo"); + list.addAll(1, m.keySet()); + } + + for (int j = 0; j < 1; j++) { + Map m = new HashMap(100); + for (int i = 0; i < 100; i++) + m.put(new Object(), Boolean.TRUE); + List list = new LinkedList(); + list.add("inka"); list.add("dinka"); list.add("doo"); + list.addAll(1, m.keySet()); + } + + for (int j = 0; j < 1; j++) { + Map m = new HashMap(100); + for (int i = 0; i < 100; i++) + m.put(new Object(), Boolean.TRUE); + List list = new ArrayList(); + list.add("inka"); list.add("dinka"); list.add("doo"); + list.addAll(1, m.keySet()); + } + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/list/ArrayList/AnonymousArrayListTest.java b/tests/src/main/java/approximations/java/util/list/ArrayList/AnonymousArrayListTest.java new file mode 100644 index 00000000..9a9c3965 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/list/ArrayList/AnonymousArrayListTest.java @@ -0,0 +1,27 @@ +package approximations.java.util.list.ArrayList; + +import approximations.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.ListIterator; + +@Test +public class AnonymousArrayListTest { + @Test(disabled = true) + // TODO: implement anonymous classes + public int test_anonymousArrayList(int execution) { + final List superstitious = new ArrayList() { + public void add(int index, Integer i) { + if (i == 0) throw new Error("unlucky"); + else super.add(index, i); }}; + final ListIterator it = superstitious.listIterator(0); + try { + it.add(123); + return -1; + } catch (Error e) { + } + it.add(42); + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/list/ArrayList/ArrayManagementTest.java b/tests/src/main/java/approximations/java/util/list/ArrayList/ArrayManagementTest.java new file mode 100644 index 00000000..23472f54 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/list/ArrayList/ArrayManagementTest.java @@ -0,0 +1,25 @@ +package approximations.java.util.list.ArrayList; + +import approximations.Test; + +import java.lang.reflect.Field; +import java.util.*; + +@Test +public class ArrayManagementTest { + @Test + public int test_negativeCapacity(int execution) { + try { + for (int capacity : new int[]{-1, Integer.MIN_VALUE}) { + try { + new ArrayList<>(capacity); + return -1; + } catch (IllegalArgumentException success) { + } + } + } catch (Throwable t) { + return -1; + } + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/list/ArrayList/EnsureCapacityTest.java b/tests/src/main/java/approximations/java/util/list/ArrayList/EnsureCapacityTest.java new file mode 100644 index 00000000..5e460679 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/list/ArrayList/EnsureCapacityTest.java @@ -0,0 +1,20 @@ +package approximations.java.util.list.ArrayList; + +import approximations.Test; + +import java.util.ArrayList; + +@Test +public class EnsureCapacityTest { + @Test + public static int test_ensureCapacity(int execution) { + testArrayList(); + return execution; + } + + private static void testArrayList() { + ArrayList al = new ArrayList<>(); + al.add("abc"); + al.ensureCapacity(Integer.MIN_VALUE); + } +} diff --git a/tests/src/main/java/approximations/java/util/list/ArrayList/SubListModCoundTest.java b/tests/src/main/java/approximations/java/util/list/ArrayList/SubListModCoundTest.java new file mode 100644 index 00000000..3843721b --- /dev/null +++ b/tests/src/main/java/approximations/java/util/list/ArrayList/SubListModCoundTest.java @@ -0,0 +1,39 @@ +package approximations.java.util.list.ArrayList; + +import approximations.Test; + +import java.util.ArrayList; +import java.util.ConcurrentModificationException; +import java.util.List; + +@Test +public class SubListModCoundTest { + @Test + public static int test_subListModCound(int execution) { + ArrayList root = new ArrayList<>(); + java.util.List subList = root.subList(0, 0); + root.add(42); + try { + subList.size(); + return -1; + } catch (ConcurrentModificationException expected) { + } + List subSubList = subList.subList(0, 0); + try { + subSubList.size(); + return -1; + } catch (ConcurrentModificationException expected) { + } + try { + subSubList.add(42); + return -1; + } catch (ConcurrentModificationException expected) { + } + try { + subList.size(); + return -1; + } catch (ConcurrentModificationException expected) { + } + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/list/LinkedList/AddAllTest.java b/tests/src/main/java/approximations/java/util/list/LinkedList/AddAllTest.java new file mode 100644 index 00000000..34aae481 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/list/LinkedList/AddAllTest.java @@ -0,0 +1,24 @@ +package approximations.java.util.list.LinkedList; + +import approximations.Test; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +@Test +public class AddAllTest { + @Test + public static int test_AddAll(int execution) { + List head = Collections.nCopies(7, "deadly sin"); + List tail = Collections.nCopies(4, "basic food group"); + List l1 = new ArrayList(head); + List l2 = new LinkedList(head); + l1.addAll(tail); + l2.addAll(tail); + if (!l1.equals(l2)) + return -1; + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/list/LinkedList/CloneTest.java b/tests/src/main/java/approximations/java/util/list/LinkedList/CloneTest.java new file mode 100644 index 00000000..404af31e --- /dev/null +++ b/tests/src/main/java/approximations/java/util/list/LinkedList/CloneTest.java @@ -0,0 +1,27 @@ +package approximations.java.util.list.LinkedList; + +import approximations.Test; + +import java.util.LinkedList; + +@Test +public class CloneTest { + @Test + public static int test_Clone(int execution) { + LinkedList2 l = new LinkedList2(); + LinkedList2 lClone = (LinkedList2) l.clone(); + if (!(l.equals(lClone) && lClone.equals(l))) + return -1; + l.add("a"); + lClone = (LinkedList2) l.clone(); + if (!(l.equals(lClone) && lClone.equals(l))) + return -1; + l.add("b"); + lClone = (LinkedList2) l.clone(); + if (!(l.equals(lClone) && lClone.equals(l))) + return -1; + return execution; + } + + private static class LinkedList2 extends LinkedList {} +} diff --git a/tests/src/main/java/approximations/java/util/list/LinkedList/ComodifiedRemoveTest.java b/tests/src/main/java/approximations/java/util/list/LinkedList/ComodifiedRemoveTest.java new file mode 100644 index 00000000..da2ce0e0 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/list/LinkedList/ComodifiedRemoveTest.java @@ -0,0 +1,30 @@ +package approximations.java.util.list.LinkedList; + +import approximations.Test; + +import java.util.ConcurrentModificationException; +import java.util.LinkedList; +import java.util.List; +import java.util.ListIterator; + +@Test +public class ComodifiedRemoveTest { + @Test + public static int test_ComodifiedRemove(int execution) { + List list = new LinkedList(); + Object o1 = 1; + list.add(o1); + ListIterator e = list.listIterator(); + e.next(); + Object o2 = 2; + list.add(o2); + + try { + e.remove(); + } catch (ConcurrentModificationException cme) { + return execution; + } + + return -1; + } +} diff --git a/tests/src/main/java/approximations/java/util/list/LinkedList/RemoveTest.java b/tests/src/main/java/approximations/java/util/list/LinkedList/RemoveTest.java new file mode 100644 index 00000000..2a7546ec --- /dev/null +++ b/tests/src/main/java/approximations/java/util/list/LinkedList/RemoveTest.java @@ -0,0 +1,24 @@ +package approximations.java.util.list.LinkedList; + +import approximations.Test; + +import java.util.LinkedList; +import java.util.ListIterator; + +@Test +public class RemoveTest { + @Test + public static int test_Remove(int execution) { + LinkedList list = new LinkedList(); + ListIterator e = list.listIterator(); + Object o = 1; + e.add(o); + e.previous(); + e.next(); + e.remove(); + e.add(o); + if (!o.equals(list.get(0))) + return -1; + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/list/List/ListDefaultsTest.java b/tests/src/main/java/approximations/java/util/list/List/ListDefaultsTest.java new file mode 100644 index 00000000..744a58d3 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/list/List/ListDefaultsTest.java @@ -0,0 +1,482 @@ +package approximations.java.util.list.List; + +import approximations.Test; + +import java.util.*; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Predicate; + +public class ListDefaultsTest { + // Suppliers of lists that can support structural modifications + /*private static final List[] LIST_STRUCT_MOD_SUPPLIERS = new List[] { new ArrayList(), new LinkedList() }; + + // Suppliers of lists that can support in place modifications + private static final List[] LIST_SUPPLIERS = new List[]{(} + java.util.ArrayList::new, + java.util.LinkedList::new, + c -> Arrays.asList(c.toArray()) + ); + + // Suppliers of lists supporting CMEs + private static final List> LIST_CME_SUPPLIERS = Arrays.asList( + java.util.ArrayList::new + ); + + private static final Predicate pEven = x -> 0 == x % 2; + private static final Predicate pOdd = x -> 1 == x % 2; + + private static final Comparator BIT_COUNT_COMPARATOR = + (x, y) -> Integer.bitCount(x) - Integer.bitCount(y); + + private static final Comparator ATOMIC_INTEGER_COMPARATOR = + (x, y) -> x.intValue() - y.intValue(); + + private static final int SIZE = 100; + private static final int SUBLIST_FROM = 20; + private static final int SUBLIST_TO = SIZE - 5; + private static final int SUBLIST_SIZE = SUBLIST_TO - SUBLIST_FROM; + + // call the callback for each recursive subList + private void trimmedSubList(final List list, final Consumer> callback) { + int size = list.size(); + if (size > 1) { + // trim 1 element from both ends + final List subList = list.subList(1, size - 1); + callback.accept(subList); + trimmedSubList(subList, callback); + } + } + + public static List> getListCases() { + final List> cases = new LinkedList<>(); + //cases.add(Collections.emptyList()); + cases.add(new ArrayList<>()); + cases.add(new LinkedList<>()); + cases.add(Arrays.asList()); + + List l = Arrays.asList(42); + cases.add(new ArrayList<>(l)); + cases.add(new LinkedList<>(l)); + return cases; + } + List> listCases = getListCases(); + + @Test(executionMax = 5) + public int test_ProvidedWithNull(int execution) { + List list = listCases.get(execution); + try { + list.forEach(null); + return -1; + } catch (NullPointerException npe) {} + try { + list.replaceAll(null); + return -1; + } catch (NullPointerException npe) {} + try { + list.removeIf(null); + return -1; + } catch (NullPointerException npe) {} + try { + list.sort(null); + } catch (Throwable t) { + return -1; + } + return execution; + } + + @Test + public int testForEach() { + final CollectionSupplier> supplier = new CollectionSupplier(LIST_SUPPLIERS, SIZE); + for (final CollectionSupplier.TestCase> test : supplier.get()) { + final List original = test.expected; + final List list = test.collection; + + try { + list.forEach(null); + fail("expected NPE not thrown"); + } catch (NullPointerException npe) {} + CollectionAsserts.assertContents(list, original); + + final List actual = new LinkedList<>(); + list.forEach(actual::add); + CollectionAsserts.assertContents(actual, list); + CollectionAsserts.assertContents(actual, original); + + if (original.size() > SUBLIST_SIZE) { + final List subList = original.subList(SUBLIST_FROM, SUBLIST_TO); + final List actualSubList = new LinkedList<>(); + subList.forEach(actualSubList::add); + assertEquals(actualSubList.size(), SUBLIST_SIZE); + for (int i = 0; i < SUBLIST_SIZE; i++) { + assertEquals(actualSubList.get(i), original.get(i + SUBLIST_FROM)); + } + } + + trimmedSubList(list, l -> { + final List a = new LinkedList<>(); + l.forEach(a::add); + CollectionAsserts.assertContents(a, l); + }); + } + } + + @Test + public void testRemoveIf() { + @SuppressWarnings("unchecked") + final CollectionSupplier> supplier = new CollectionSupplier(LIST_STRUCT_MOD_SUPPLIERS, SIZE); + for (final CollectionSupplier.TestCase> test : supplier.get()) { + final List original = test.expected; + final List list = test.collection; + + try { + list.removeIf(null); + fail("expected NPE not thrown"); + } catch (NullPointerException npe) {} + CollectionAsserts.assertContents(list, original); + + final AtomicInteger offset = new AtomicInteger(1); + while (list.size() > 0) { + removeFirst(original, list, offset); + } + } + + for (final CollectionSupplier.TestCase> test : supplier.get()) { + final List original = test.expected; + final List list = test.collection; + list.removeIf(pOdd); + for (int i : list) { + assertTrue((i % 2) == 0); + } + for (int i : original) { + if (i % 2 == 0) { + assertTrue(list.contains(i)); + } + } + list.removeIf(pEven); + assertTrue(list.isEmpty()); + } + + for (final CollectionSupplier.TestCase> test : supplier.get()) { + final List original = test.expected; + final List list = test.collection; + final List listCopy = new ArrayList<>(list); + if (original.size() > SUBLIST_SIZE) { + final List subList = list.subList(SUBLIST_FROM, SUBLIST_TO); + final List subListCopy = new ArrayList<>(subList); + listCopy.removeAll(subList); + subList.removeIf(pOdd); + for (int i : subList) { + assertTrue((i % 2) == 0); + } + for (int i : subListCopy) { + if (i % 2 == 0) { + assertTrue(subList.contains(i)); + } else { + assertFalse(subList.contains(i)); + } + } + subList.removeIf(pEven); + assertTrue(subList.isEmpty()); + // elements outside the view should remain + CollectionAsserts.assertContents(list, listCopy); + } + } + + for (final CollectionSupplier.TestCase> test : supplier.get()) { + final List list = test.collection; + trimmedSubList(list, l -> { + final List copy = new ArrayList<>(l); + l.removeIf(pOdd); + for (int i : l) { + assertTrue((i % 2) == 0); + } + for (int i : copy) { + if (i % 2 == 0) { + assertTrue(l.contains(i)); + } else { + assertFalse(l.contains(i)); + } + } + }); + } + } + + // remove the first element + private void removeFirst(final List original, final List list, final AtomicInteger offset) { + final AtomicBoolean first = new AtomicBoolean(true); + list.removeIf(x -> first.getAndSet(false)); + CollectionAsserts.assertContents(original.subList(offset.getAndIncrement(), original.size()), list); + } + + @Test + public void testReplaceAll() { + final int scale = 3; + @SuppressWarnings("unchecked") + final CollectionSupplier> supplier = new CollectionSupplier(LIST_SUPPLIERS, SIZE); + for (final CollectionSupplier.TestCase> test : supplier.get()) { + final List original = test.expected; + final List list = test.collection; + + try { + list.replaceAll(null); + fail("expected NPE not thrown"); + } catch (NullPointerException npe) {} + CollectionAsserts.assertContents(list, original); + + list.replaceAll(x -> scale * x); + for (int i = 0; i < original.size(); i++) { + assertTrue(list.get(i) == (scale * original.get(i)), "mismatch at index " + i); + } + + if (original.size() > SUBLIST_SIZE) { + final List subList = list.subList(SUBLIST_FROM, SUBLIST_TO); + subList.replaceAll(x -> x + 1); + // verify elements in view [from, to) were replaced + for (int i = 0; i < SUBLIST_SIZE; i++) { + assertTrue(subList.get(i) == ((scale * original.get(i + SUBLIST_FROM)) + 1), + "mismatch at sublist index " + i); + } + // verify that elements [0, from) remain unmodified + for (int i = 0; i < SUBLIST_FROM; i++) { + assertTrue(list.get(i) == (scale * original.get(i)), + "mismatch at original index " + i); + } + // verify that elements [to, size) remain unmodified + for (int i = SUBLIST_TO; i < list.size(); i++) { + assertTrue(list.get(i) == (scale * original.get(i)), + "mismatch at original index " + i); + } + } + } + + for (final CollectionSupplier.TestCase> test : supplier.get()) { + final List list = test.collection; + trimmedSubList(list, l -> { + final List copy = new ArrayList<>(l); + final int offset = 5; + l.replaceAll(x -> offset + x); + for (int i = 0; i < copy.size(); i++) { + assertTrue(l.get(i) == (offset + copy.get(i)), "mismatch at index " + i); + } + }); + } + } + + @Test + public void testSort() { + @SuppressWarnings("unchecked") + final CollectionSupplier> supplier = new CollectionSupplier(LIST_SUPPLIERS, SIZE); + for (final CollectionSupplier.TestCase> test : supplier.get()) { + final List original = test.expected; + final List list = test.collection; + CollectionSupplier.shuffle(list); + list.sort(Integer::compare); + CollectionAsserts.assertSorted(list, Integer::compare); + if (test.name.startsWith("reverse")) { + Collections.reverse(list); + } + CollectionAsserts.assertContents(list, original); + + CollectionSupplier.shuffle(list); + list.sort(null); + CollectionAsserts.assertSorted(list, Comparator.naturalOrder()); + if (test.name.startsWith("reverse")) { + Collections.reverse(list); + } + CollectionAsserts.assertContents(list, original); + + CollectionSupplier.shuffle(list); + list.sort(Comparator.naturalOrder()); + CollectionAsserts.assertSorted(list, Comparator.naturalOrder()); + if (test.name.startsWith("reverse")) { + Collections.reverse(list); + } + CollectionAsserts.assertContents(list, original); + + CollectionSupplier.shuffle(list); + list.sort(Comparator.reverseOrder()); + CollectionAsserts.assertSorted(list, Comparator.reverseOrder()); + if (!test.name.startsWith("reverse")) { + Collections.reverse(list); + } + CollectionAsserts.assertContents(list, original); + + CollectionSupplier.shuffle(list); + list.sort(BIT_COUNT_COMPARATOR); + CollectionAsserts.assertSorted(list, BIT_COUNT_COMPARATOR); + // check sort by verifying that bitCount increases and never drops + int minBitCount = 0; + for (final Integer i : list) { + int bitCount = Integer.bitCount(i); + assertTrue(bitCount >= minBitCount); + minBitCount = bitCount; + } + + // Reuse the supplier to store AtomicInteger instead of Integer + // Hence the use of raw type and cast + List incomparablesData = new ArrayList<>(); + for (int i = 0; i < test.expected.size(); i++) { + incomparablesData.add(new AtomicInteger(i)); + } + Function f = test.supplier; + @SuppressWarnings("unchecked") + List incomparables = (List) f.apply(incomparablesData); + + CollectionSupplier.shuffle(incomparables); + incomparables.sort(ATOMIC_INTEGER_COMPARATOR); + for (int i = 0; i < test.expected.size(); i++) { + assertEquals(i, incomparables.get(i).intValue()); + } + + + if (original.size() > SUBLIST_SIZE) { + final List copy = new ArrayList<>(list); + final List subList = list.subList(SUBLIST_FROM, SUBLIST_TO); + CollectionSupplier.shuffle(subList); + subList.sort(Comparator.naturalOrder()); + CollectionAsserts.assertSorted(subList, Comparator.naturalOrder()); + // verify that elements [0, from) remain unmodified + for (int i = 0; i < SUBLIST_FROM; i++) { + assertTrue(list.get(i) == copy.get(i), + "mismatch at index " + i); + } + // verify that elements [to, size) remain unmodified + for (int i = SUBLIST_TO; i < list.size(); i++) { + assertTrue(list.get(i) == copy.get(i), + "mismatch at index " + i); + } + } + } + + for (final CollectionSupplier.TestCase> test : supplier.get()) { + final List list = test.collection; + trimmedSubList(list, l -> { + CollectionSupplier.shuffle(l); + l.sort(Comparator.naturalOrder()); + CollectionAsserts.assertSorted(l, Comparator.naturalOrder()); + }); + } + } + + @Test + public void testForEachThrowsCME() { + @SuppressWarnings("unchecked") + final CollectionSupplier> supplier = new CollectionSupplier(LIST_CME_SUPPLIERS, SIZE); + for (final CollectionSupplier.TestCase> test : supplier.get()) { + final List list = test.collection; + + if (list.size() <= 1) { + continue; + } + boolean gotException = false; + try { + // bad predicate that modifies its list, should throw CME + list.forEach(list::add); + } catch (ConcurrentModificationException cme) { + gotException = true; + } + if (!gotException) { + fail("expected CME was not thrown from " + test); + } + } + } + + @Test + public void testRemoveIfThrowsCME() { + @SuppressWarnings("unchecked") + final CollectionSupplier> supplier = new CollectionSupplier(LIST_CME_SUPPLIERS, SIZE); + for (final CollectionSupplier.TestCase> test : supplier.get()) { + final List list = test.collection; + + if (list.size() <= 1) { + continue; + } + boolean gotException = false; + try { + // bad predicate that modifies its list, should throw CME + list.removeIf(list::add); + } catch (ConcurrentModificationException cme) { + gotException = true; + } + if (!gotException) { + fail("expected CME was not thrown from " + test); + } + } + } + + @Test + public void testReplaceAllThrowsCME() { + @SuppressWarnings("unchecked") + final CollectionSupplier> supplier = new CollectionSupplier(LIST_CME_SUPPLIERS, SIZE); + for (final CollectionSupplier.TestCase> test : supplier.get()) { + final List list = test.collection; + + if (list.size() <= 1) { + continue; + } + boolean gotException = false; + try { + // bad predicate that modifies its list, should throw CME + list.replaceAll(x -> {int n = 3 * x; list.add(n); return n;}); + } catch (ConcurrentModificationException cme) { + gotException = true; + } + if (!gotException) { + fail("expected CME was not thrown from " + test); + } + } + } + + @Test + public void testSortThrowsCME() { + @SuppressWarnings("unchecked") + final CollectionSupplier> supplier = new CollectionSupplier(LIST_CME_SUPPLIERS, SIZE); + for (final CollectionSupplier.TestCase> test : supplier.get()) { + final List list = test.collection; + + if (list.size() <= 1) { + continue; + } + boolean gotException = false; + try { + // bad predicate that modifies its list, should throw CME + list.sort((x, y) -> {list.add(x); return x - y;}); + } catch (ConcurrentModificationException cme) { + gotException = true; + } + if (!gotException) { + fail("expected CME was not thrown from " + test); + } + } + } + + private static final List SLICED_EXPECTED = Arrays.asList(0, 1, 2, 3, 5, 6, 7, 8, 9); + private static final List SLICED_EXPECTED2 = Arrays.asList(0, 1, 2, 5, 6, 7, 8, 9); + + @DataProvider(name="shortIntListProvider", parallel=true) + public static Object[][] intListCases() { + final Integer[] DATA = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + final List cases = new LinkedList<>(); + cases.add(new Object[] { new ArrayList<>(Arrays.asList(DATA)) }); + cases.add(new Object[] { new LinkedList<>(Arrays.asList(DATA)) }); + cases.add(new Object[] { new Vector<>(Arrays.asList(DATA)) }); + cases.add(new Object[] { new CopyOnWriteArrayList<>(Arrays.asList(DATA)) }); + cases.add(new Object[] { new ExtendsAbstractList<>(Arrays.asList(DATA)) }); + return cases.toArray(new Object[0][cases.size()]); + } + + @Test(dataProvider = "shortIntListProvider") + public void testRemoveIfFromSlice(final List list) { + final List sublist = list.subList(3, 6); + assertTrue(sublist.removeIf(x -> x == 4)); + CollectionAsserts.assertContents(list, SLICED_EXPECTED); + + final List sublist2 = list.subList(2, 5); + assertTrue(sublist2.removeIf(x -> x == 3)); + CollectionAsserts.assertContents(list, SLICED_EXPECTED2); + }*/ +} diff --git a/tests/src/main/java/approximations/java/util/list/List/ListFactoriesTest.java b/tests/src/main/java/approximations/java/util/list/List/ListFactoriesTest.java new file mode 100644 index 00000000..e8583467 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/list/List/ListFactoriesTest.java @@ -0,0 +1,607 @@ +package approximations.java.util.list.List; + +import approximations.Test; + +import java.util.List; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.ListIterator; + +import static java.util.Arrays.asList; + +public class ListFactoriesTest { + /*public static List List_of() { + return new ArrayList<>(); + }*/ + + public static List List_of(T[] elements) { + return new ArrayList<>(asList(elements)); + } + + static final int NUM_STRINGS = 20; // should be larger than the largest fixed-arg overload + static final String[] stringArray; + static { + String[] sa = new String[NUM_STRINGS]; + for (int i = 0; i < NUM_STRINGS; i++) { + sa[i] = String.valueOf((char)('a' + i)); + } + stringArray = sa; + } + + // returns array of [actual, expected] + static Object[] a(List act, List exp) { + return new Object[] { act, exp }; + } + + /*@DataProvider(name="empty") + public Iterator empty() { + return Collections.singletonList( + a(List_of(), asList()) + ).iterator(); + }*/ + + static final Object[] empty = a(List_of(new String[] {}), asList()); + + /*@DataProvider(name="nonempty") + public Iterator nonempty() { + return asList( + a(List_of(new String[] { "a" } ), + asList("a")), + a(List_of(new String[] { "a", "b" }), + asList("a", "b")), + a(List_of(new String[] { "a", "b", "c" }), + asList("a", "b", "c")), + a(List_of(new String[] { "a", "b", "c", "d" }), + asList("a", "b", "c", "d")), + a(List_of(new String[] { "a", "b", "c", "d", "e" }), + asList("a", "b", "c", "d", "e")), + a(List_of(new String[] { "a", "b", "c", "d", "e", "f" }), + asList("a", "b", "c", "d", "e", "f")), + a(List_of(new String[] { "a", "b", "c", "d", "e", "f", "g" }), + asList("a", "b", "c", "d", "e", "f", "g")), + a(List_of(new String[] { "a", "b", "c", "d", "e", "f", "g", "h" }), + asList("a", "b", "c", "d", "e", "f", "g", "h")), + a(List_of(new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i" }), + asList("a", "b", "c", "d", "e", "f", "g", "h", "i")), + a(List_of(new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }), + asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j")), + a(List_of(stringArray), + asList(stringArray)) + ).iterator(); + }*/ + + static final List nonempty = asList( + a(List_of(new String[] { "a" } ), + asList("a")), + a(List_of(new String[] { "a", "b" }), + asList("a", "b")), + a(List_of(new String[] { "a", "b", "c" }), + asList("a", "b", "c")), + a(List_of(new String[] { "a", "b", "c", "d" }), + asList("a", "b", "c", "d")), + a(List_of(new String[] { "a", "b", "c", "d", "e" }), + asList("a", "b", "c", "d", "e")), + a(List_of(new String[] { "a", "b", "c", "d", "e", "f" }), + asList("a", "b", "c", "d", "e", "f")), + a(List_of(new String[] { "a", "b", "c", "d", "e", "f", "g" }), + asList("a", "b", "c", "d", "e", "f", "g")), + a(List_of(new String[] { "a", "b", "c", "d", "e", "f", "g", "h" }), + asList("a", "b", "c", "d", "e", "f", "g", "h")), + a(List_of(new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i" }), + asList("a", "b", "c", "d", "e", "f", "g", "h", "i")), + a(List_of(new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }), + asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j")), + a(List_of(stringArray), + asList(stringArray))); + + /*@DataProvider(name="sublists") + public Iterator sublists() { + return asList( + a((new ArrayList()).subList(0,0), + asList()), + a(List_of(new String[] { "a" }).subList(0,0), + asList("a").subList(0,0)), + a(List_of(new String[] { "a", "b" }).subList(0,1), + asList("a", "b").subList(0,1)), + a(List_of(new String[] { "a", "b", "c" }).subList(1,3), + asList("a", "b", "c").subList(1,3)), + a(List_of(new String[] { "a", "b", "c", "d" }).subList(0,4), + asList("a", "b", "c", "d").subList(0,4)), + a(List_of(new String[] { "a", "b", "c", "d", "e" }).subList(0,3), + asList("a", "b", "c", "d", "e").subList(0,3)), + a(List_of(new String[] { "a", "b", "c", "d", "e", "f" }).subList(3, 5), + asList("a", "b", "c", "d", "e", "f").subList(3, 5)), + a(List_of(new String[] { "a", "b", "c", "d", "e", "f", "g" }).subList(0, 7), + asList("a", "b", "c", "d", "e", "f", "g").subList(0, 7)), + a(List_of(new String[] { "a", "b", "c", "d", "e", "f", "g", "h" }).subList(0, 0), + asList("a", "b", "c", "d", "e", "f", "g", "h").subList(0, 0)), + a(List_of(new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i" }).subList(4, 5), + asList("a", "b", "c", "d", "e", "f", "g", "h", "i").subList(4, 5)), + a(List_of(new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }).subList(1,10), + asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j").subList(1,10)), + a(List_of(stringArray).subList(5, NUM_STRINGS), + asList(Arrays.copyOfRange(stringArray, 5, NUM_STRINGS))) + ).iterator(); + }*/ + + static final List sublists = asList( + a((new ArrayList()).subList(0,0), + asList()), + a(List_of(new String[] { "a" }).subList(0,0), + asList("a").subList(0,0)), + a(List_of(new String[] { "a", "b" }).subList(0,1), + asList("a", "b").subList(0,1)), + a(List_of(new String[] { "a", "b", "c" }).subList(1,3), + asList("a", "b", "c").subList(1,3)), + a(List_of(new String[] { "a", "b", "c", "d" }).subList(0,4), + asList("a", "b", "c", "d").subList(0,4)), + a(List_of(new String[] { "a", "b", "c", "d", "e" }).subList(0,3), + asList("a", "b", "c", "d", "e").subList(0,3)), + a(List_of(new String[] { "a", "b", "c", "d", "e", "f" }).subList(3, 5), + asList("a", "b", "c", "d", "e", "f").subList(3, 5)), + a(List_of(new String[] { "a", "b", "c", "d", "e", "f", "g" }).subList(0, 7), + asList("a", "b", "c", "d", "e", "f", "g").subList(0, 7)), + a(List_of(new String[] { "a", "b", "c", "d", "e", "f", "g", "h" }).subList(0, 0), + asList("a", "b", "c", "d", "e", "f", "g", "h").subList(0, 0)), + a(List_of(new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i" }).subList(4, 5), + asList("a", "b", "c", "d", "e", "f", "g", "h", "i").subList(4, 5)), + a(List_of(new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }).subList(1,10), + asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j").subList(1,10)), + a(List_of(stringArray).subList(5, NUM_STRINGS), + asList(Arrays.copyOfRange(stringArray, 5, NUM_STRINGS)))); + + //@DataProvider(name="all") + public static List getAll() { + List all = new ArrayList<>(); + /*empty().forEachRemaining(all::add); + nonempty().forEachRemaining(all::add); + sublists().forEachRemaining(all::add); + return all.iterator();*/ + all.add(empty); + all.addAll(nonempty); + all.addAll(sublists); + return all; + } + static final List all = getAll(); + + //@DataProvider(name="nonsublists") + public static List getNonsublists() { + List all = new ArrayList<>(); + /*empty().forEachRemaining(all::add); + nonempty().forEachRemaining(all::add); + return all.iterator();*/ + all.add(empty); + all.addAll(nonempty); + return all; + } + static final List nonsublists = getNonsublists(); + + //@Test(dataProvider="all", expectedExceptions=UnsupportedOperationException.class) + @Test(executionMax = 23) + public static int test_cannotAddLast(int execution) { + List act = (List) all.get(execution)[0]; + try { + act.add("x"); + return -1; + } catch (UnsupportedOperationException e) { + return execution; + } + } + + //@Test(dataProvider="all", expectedExceptions=UnsupportedOperationException.class) + @Test(executionMax = 23) + public static int test_cannotAddFirst(int execution) { + List act = (List) all.get(execution)[0]; + try { + act.add(0, "x"); + return -1; + } catch (UnsupportedOperationException e) { + return execution; + } + } + + //@Test(dataProvider="nonempty", expectedExceptions=UnsupportedOperationException.class) + @Test(executionMax = 10) + public static int test_cannotRemove(int execution) { + List act = (List) nonempty.get(execution)[0]; + try { + act.remove(0); + return -1; + } catch (UnsupportedOperationException e) { + return execution; + } + } + + //@Test(dataProvider="nonempty", expectedExceptions=UnsupportedOperationException.class) + @Test(executionMax = 10) + public static int test_cannotSet(int execution) { + List act = (List) nonempty.get(execution)[0]; + try { + act.set(0, "x"); + return -1; + } catch (UnsupportedOperationException e) { + return execution; + } + } + + //@Test(dataProvider="all") + @Test(executionMax = 23) + public static int test_contentsMatch(int execution) { + List act = (List) all.get(execution)[0]; + List exp = (List) all.get(execution)[1]; + //assertEquals(act, exp); + if (!act.equals(exp)) { + return -1; + } else { + return execution; + } + } + + //@Test(expectedExceptions=NullPointerException.class) + @Test + public static int test_nullDisallowed1(int execution) { + try { + List_of(new Object[] { null }); // force one-arg overload + return -1; + } catch (NullPointerException e) { + return execution; + } + } + + //@Test(expectedExceptions=NullPointerException.class) + /*@Test + public static int test_nullDisallowed2a(int execution) { + try { + List_of(new String[] { "a", null }); + return -1; + } catch (NullPointerException e) { + return execution; + } + } + + //@Test(expectedExceptions=NullPointerException.class) + @Test + public static int test_nullDisallowed2b(int execution) { + try { + List_of(new String[] { null, "b" }); + return -1; + } catch (NullPointerException e) { + return execution; + } + } + + //@Test(expectedExceptions=NullPointerException.class) + @Test + public static int test_nullDisallowed3(int execution) { + try { + List_of(new String[] { "a", "b", null }); + return -1; + } catch (NullPointerException e) { + return execution; + } + } + + //@Test(expectedExceptions=NullPointerException.class) + @Test + public static int test_nullDisallowed4(int execution) { + try { + List_of(new String[] { "a", "b", "c", null }); + return -1; + } catch (NullPointerException e) { + return execution; + } + } + + //@Test(expectedExceptions=NullPointerException.class) + @Test + public static int test_nullDisallowed5(int execution) { + try { + List_of(new String[] { "a", "b", "c", "d", null }); + return -1; + } catch (NullPointerException e) { + return execution; + } + } + + //@Test(expectedExceptions=NullPointerException.class) + @Test + public static int test_nullDisallowed6(int execution) { + try { + List_of(new String[] { "a", "b", "c", "d", "e", null }); + return -1; + } catch (NullPointerException e) { + return execution; + } + } + + //@Test(expectedExceptions=NullPointerException.class) + @Test + public static int test_nullDisallowed7(int execution) { + try { + List_of(new String[] { "a", "b", "c", "d", "e", "f", null }); + return -1; + } catch (NullPointerException e) { + return execution; + } + } + + //@Test(expectedExceptions=NullPointerException.class) + @Test + public static int test_nullDisallowed8(int execution) { + try { + List_of(new String[] { "a", "b", "c", "d", "e", "f", "g", null }); + return -1; + } catch (NullPointerException e) { + return execution; + } + } + + //@Test(expectedExceptions=NullPointerException.class) + @Test + public static int test_nullDisallowed9(int execution) { + try { + List.of("a", "b", "c", "d", "e", "f", "g", "h", null); + }*/ + + //@Test(expectedExceptions=NullPointerException.class) + @Test + public static int test_nullDisallowed10(int execution) { + try { + List_of(new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", null }); + return -1; + } catch (NullPointerException e) { + return execution; + } + } + + //@Test(expectedExceptions=NullPointerException.class) + @Test + public static int test_nullDisallowedN(int execution) { + try { + String[] array = stringArray.clone(); + array[0] = null; + List_of(array); + return -1; + } catch (NullPointerException e) { + return execution; + } + } + + //@Test(expectedExceptions=NullPointerException.class) + @Test + public static int test_nullArrayDisallowed(int execution) { + try { + List_of(null); + return -1; + } catch (NullPointerException e) { + return execution; + } + } + + @Test + public static int test_ensureArrayCannotModifyList(int execution) { + String[] array = stringArray.clone(); + List list = List_of(array); + array[0] = "xyzzy"; + //assertEquals(list, Arrays.asList(stringArray)); + if (!list.equals(Arrays.asList(stringArray))) { + return -1; + } else { + return execution; + } + } + + //@Test(dataProvider="all", expectedExceptions=NullPointerException.class) + @Test(executionMax = 23) + public static int test_containsNullShouldThrowNPE(int execution) { + try { + List act = (List) all.get(execution)[0]; + act.contains(null); + return -1; + } catch (NullPointerException e) { + return execution; + } + } + + //@Test(dataProvider="all", expectedExceptions=NullPointerException.class) + @Test(executionMax = 23) + public static int test_indexOfNullShouldThrowNPE(int execution) { + try { + List act = (List) all.get(execution)[0]; + act.indexOf(null); + return -1; + } catch (NullPointerException e) { + return execution; + } + } + + //@Test(dataProvider="all", expectedExceptions=NullPointerException.class) + @Test(executionMax = 23) + public static int test_lastIndexOfNullShouldThrowNPE(int execution) { + try { + List act = (List) all.get(execution)[0]; + act.lastIndexOf(null); + return -1; + } catch (NullPointerException e) { + return execution; + } + } + + // List.of().subList views should not be Serializable + //@Test(dataProvider="sublists") + @Test(executionMax = 11) + public static int test_isNotSerializable(int execution) { + List act = (List) sublists.get(execution)[0]; + //assertFalse(act instanceof Serializable); + if (act instanceof Serializable) { + return -1; + } else { + return execution; + } + } + + // ... but List.of() should be + //@Test(dataProvider="nonsublists") + @Test(executionMax = 11) + public static int test_serialEquality(int execution) { + // assume that act.equals(exp) tested elsewhere + List act = (List) nonsublists.get(execution)[0]; + List copy = new ArrayList<>(); + copy.addAll(act); + if (!act.equals(copy) || !copy.equals(act)) { + return -1; + } else { + return execution; + } + /*assertEquals(act, copy); + assertEquals(copy, exp);*/ + } + + /*@SuppressWarnings("unchecked") + static T serialClone(T obj) { + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(obj); + } + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ObjectInputStream ois = new ObjectInputStream(bais); + return (T) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new AssertionError(e); + } + }*/ + + static List genList() { + return new ArrayList<>(Arrays.asList(1, 2, 3)); + } + + @Test + public static int test_copyOfResultsEqual(int execution) { + List orig = genList(); + List copy = new ArrayList<>(orig); + if (!orig.equals(copy) || !copy.equals(orig)) { + return -1; + } else { + return execution; + } + /*assertEquals(orig, copy); + assertEquals(copy, orig);*/ + } + + @Test + public static int test_copyOfModifiedUnequal(int execution) { + List orig = genList(); + List copy = new ArrayList<>(orig); + orig.add(4); + if (orig.equals(copy) || copy.equals(orig)) { + return -1; + } else { + return execution; + } + /*assertNotEquals(orig, copy); + assertNotEquals(copy, orig);*/ + } + + @Test + public static int test_copyOfIdentity(int execution) { + List orig = genList(); + List copy1 = new ArrayList<>(orig); + List copy2 = new ArrayList<>(copy1); + if (orig == copy1 || copy1 != copy2) { + return -1; + } else { + return execution; + } + /*assertNotSame(orig, copy1); + assertSame(copy1, copy2);*/ + } + + @Test + public static int test_copyOfSubList(int execution) { + List orig = List_of(new Integer[] { 0, 1, 2, 3 }); + List sub = orig.subList(0, 3); + List copy = new ArrayList<>(sub); + if (sub == copy) { + return -1; + } else { + return execution; + } + //assertNotSame(sub, copy); + } + + @Test + public static int test_copyOfSubSubList(int execution) { + List orig = List_of(new Integer[] { 0, 1, 2, 3 }); + List sub = orig.subList(0, 3).subList(0, 2); + List copy = new ArrayList<>(sub); + if (sub == copy) { + return -1; + } else { + return execution; + } + //assertNotSame(sub, copy); + } + + //@Test(expectedExceptions=NullPointerException.class) + @Test + public static int test_copyOfRejectsNullCollection(int execution) { + try { + List list = new ArrayList<>(null); + return -1; + } catch (NullPointerException e) { + return execution; + } + } + + //@Test(expectedExceptions=NullPointerException.class) + @Test + public static int test_copyOfRejectsNullElements(int execution) { + try { + List list = new ArrayList<>(Arrays.asList(1, null, 3)); + return -1; + } catch (NullPointerException e) { + return execution; + } + } + + //@Test(expectedExceptions=NullPointerException.class) + @Test + public static int test_copyOfRejectsNullElements2(int execution) { + try { + List list = new ArrayList<>(List_of(new String[] { "a", null, "c" })); + return -1; + } catch (NullPointerException e) { + return execution; + } + } + + @Test + public static int test_copyOfCopiesNullAllowingList(int execution) { + //List orig = Stream.of("a", "b", "c").toList(); + List orig = List_of(new String[] { "a", "b", "c" }); + List copy = new ArrayList<>(orig); + if (orig == copy) { + return -1; + } else { + return execution; + } + //assertNotSame(orig, copy); + } + + @Test + public static int test_iteratorShouldNotBeListIterator(int execution) { + List list = List_of(new Integer[] { 1, 2, 3, 4, 5 }); + Iterator it = list.iterator(); + it.next(); + try { + ((ListIterator) it).previous(); + return -1; + } catch (ClassCastException|UnsupportedOperationException ignore) { + return execution; + } + } +} diff --git a/tests/src/main/java/approximations/java/util/list/List/LockStepTest.java b/tests/src/main/java/approximations/java/util/list/List/LockStepTest.java new file mode 100644 index 00000000..00d17117 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/list/List/LockStepTest.java @@ -0,0 +1,959 @@ +package approximations.java.util.list.List; + +import approximations.Test; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.ConcurrentModificationException; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.ListIterator; +import java.util.Random; + +@Test +public class LockStepTest { + //static final int DEFAULT_SIZE = 5; + static final int size = 2; // Running time is O(size**2) + + /*boolean maybe(int n) { return rnd.nextInt(n) == 0; } + + void test() { + size = DEFAULT_SIZE; + + lockSteps(new ArrayList(), + new LinkedList()); + }*/ + + static boolean equalLists(List... lists) { + for (List list : lists) { + if (!equalLists(list, lists[0])) { + return false; + } + } + return true; + } + + static boolean equalLists(List x, List y) { + /*equal(x, y); + equal(y, x); + equal(x.size(), y.size()); + equal(x.isEmpty(), y.isEmpty()); + equal(x.hashCode(), y.hashCode()); + equal(x.toString(), y.toString()); + equal(x.toArray(), y.toArray());*/ + if (!equal(x, y)) { return false; } + if (!equal(y, x)) { return false; } + if (!equal(x.size(), y.size())) { return false; } + if (!equal(x.isEmpty(), y.isEmpty())) { return false; } + //if (!equal(x.toString(), y.toString())) { return false; } + //if (!equal(x.toArray(), y.toArray())) { return false; } + return true; + } + + @Test//(executionMax = 1) + public static int test_EmptyLists(int execution) { + List[] lists = new List[] { new ArrayList()/*, new LinkedList<>()*/ }; + List list; + /*if (execution < 0 || execution > 1) { + return execution; + } + if (execution == 0) { + list = lists[0]; + } else { + list = lists[1]; + }*/ + list = lists[0]; + if(testEmptyList(list)) { + return execution; + } else { + return -1; + } + } + + public static List[] prepareLists() throws Exception { + List[] lists = new List[] { new ArrayList<>(), new LinkedList<>() }; + for (int i = 0; i < size; i++) { + ListFrobber adder = new RandomAdder(); + for (final List list : lists) { + if (!adder.frob(list)) { throw new Exception(); } + if (!equal(list.size(), i+1)) { + throw new Exception(); + } + } + + if (!equalLists(lists)) { + throw new Exception(); + } + } + return lists; + } + + @Test + public static int test_RightAfterPreparation(int execution) { + try { + prepareLists(); + return execution; + } catch (Exception e) { + return -1; + } + } + + @Test(executionMax = 1) + public static int test_CME1(int execution) { + if (execution < 0 || execution > 1) { + return execution; + } + List[] lists; + try { + lists = prepareLists(); + } catch (Exception e) { + return -1; + } + + final ListFrobber adder = new RandomAdder(); + List list; + if (execution == 0) { + list = lists[0]; + } else { + list = lists[1]; + } + try { + Iterator it = list.iterator(); + if (!adder.frob(list)) { return -1; } + it.next(); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 1) + public static int test_CME2(int execution) { + if (execution < 0 || execution > 1) { + return execution; + } + List[] lists; + try { + lists = prepareLists(); + } catch (Exception e) { + return -1; + } + + final ListFrobber remover = new RandomRemover(); + List list; + if (execution == 0) { + list = lists[0]; + } else { + list = lists[1]; + } + try { + Iterator it = asSubList(list).iterator(); + if (!remover.frob(list)) { return -1; } + it.next(); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 1) + public static int test_CME3(int execution) { + if (execution < 0 || execution > 1) { + return execution; + } + List[] lists; + try { + lists = prepareLists(); + } catch (Exception e) { + return -1; + } + + final ListFrobber adder = new RandomAdder(); + List list; + if (execution == 0) { + list = lists[0]; + } else { + list = lists[1]; + } + try { + Iterator it = asSubList(asSubList(list)).iterator(); + if (!adder.frob(list)) { return -1; } + it.next(); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 1) + public static int test_CME4(int execution) { + if (execution < 0 || execution > 1) { + return execution; + } + List[] lists; + try { + lists = prepareLists(); + } catch (Exception e) { + return -1; + } + + final ListFrobber remover = new RandomRemover(); + List list; + if (execution == 0) { + list = lists[0]; + } else { + list = lists[1]; + } + try { + List subList = asSubList(list); + if (!remover.frob(list)) { return -1; } + subList.get(0); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 1) + public static int test_CME5(int execution) { + if (execution < 0 || execution > 1) { + return execution; + } + List[] lists; + try { + lists = prepareLists(); + } catch (Exception e) { + return -1; + } + + final ListFrobber adder = new RandomAdder(); + List list; + if (execution == 0) { + list = lists[0]; + } else { + list = lists[1]; + } + try { + List sl = asSubList(list); + List ssl = asSubList(sl); + if (!adder.frob(sl)) { return -1; } + ssl.get(0); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 1) + public static int test_CME6(int execution) { + if (execution < 0 || execution > 1) { + return execution; + } + List[] lists; + try { + lists = prepareLists(); + } catch (Exception e) { + return -1; + } + + final ListFrobber remover = new RandomRemover(); + List list; + if (execution == 0) { + list = lists[0]; + } else { + list = lists[1]; + } + try { + List sl = asSubList(list); + List ssl = asSubList(sl); + if (!remover.frob(sl)) { return -1; } + ssl.get(0); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 1) + public static int test_IndexOutOfBounds1(int execution) { + if (execution < 0 || execution > 1) { + return execution; + } + List[] lists; + try { + lists = prepareLists(); + } catch (Exception e) { + return -1; + } + + List l; + if (execution == 0) { + l = lists[0]; + } else { + l = lists[1]; + } + final List sl = asSubList(l); + final List ssl = asSubList(sl); + ssl.add(0, 42); + if (!equal(ssl.get(0), 42)) { return -1; } + if (!equal(sl.get(0), 42)) { return -1; } + if (!equal(l.get(0), 42)) { return -1; } + final int rndIndex = rnd.nextInt(l.size()); + try { + l.subList(rndIndex, rndIndex).get(0); + } catch (IndexOutOfBoundsException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 1) + public static int test_IndexOutOfBounds2(int execution) { + if (execution < 0 || execution > 1) { + return execution; + } + List[] lists; + try { + lists = prepareLists(); + } catch (Exception e) { + return -1; + } + + List l; + if (execution == 0) { + l = lists[0]; + } else { + l = lists[1]; + } + final List sl = asSubList(l); + final List ssl = asSubList(sl); + ssl.add(0, 42); + if (!equal(ssl.get(0), 42)) { return -1; } + if (!equal(sl.get(0), 42)) { return -1; } + if (!equal(l.get(0), 42)) { return -1; } + final int s = l.size(); + try { + l.subList(s/2, s).get(s/2 + 1); + } catch (IndexOutOfBoundsException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 1) + public static int test_IndexOutOfBounds3(int execution) { + if (execution < 0 || execution > 1) { + return execution; + } + List[] lists; + try { + lists = prepareLists(); + } catch (Exception e) { + return -1; + } + + List l; + if (execution == 0) { + l = lists[0]; + } else { + l = lists[1]; + } + final List sl = asSubList(l); + final List ssl = asSubList(sl); + ssl.add(0, 42); + if (!equal(ssl.get(0), 42)) { return -1; } + if (!equal(sl.get(0), 42)) { return -1; } + if (!equal(l.get(0), 42)) { return -1; } + final int s = l.size(); + try { + l.subList(s/2, s).get(-1); + } catch (IndexOutOfBoundsException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 1) + public static int test_IllegalArgument1(int execution) { + if (execution < 0 || execution > 1) { + return execution; + } + List[] lists; + try { + lists = prepareLists(); + } catch (Exception e) { + return -1; + } + + List l; + if (execution == 0) { + l = lists[0]; + } else { + l = lists[1]; + } + final List sl = asSubList(l); + final List ssl = asSubList(sl); + ssl.add(0, 42); + if (!equal(ssl.get(0), 42)) { return -1; } + if (!equal(sl.get(0), 42)) { return -1; } + if (!equal(l.get(0), 42)) { return -1; } + try { + l.subList(1, 0); + } catch (IllegalArgumentException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 1) + public static int test_IllegalArgument2(int execution) { + if (execution < 0 || execution > 1) { + return execution; + } + List[] lists; + try { + lists = prepareLists(); + } catch (Exception e) { + return -1; + } + + List l; + if (execution == 0) { + l = lists[0]; + } else { + l = lists[1]; + } + final List sl = asSubList(l); + final List ssl = asSubList(sl); + ssl.add(0, 42); + if (!equal(ssl.get(0), 42)) { return -1; } + if (!equal(sl.get(0), 42)) { return -1; } + if (!equal(l.get(0), 42)) { return -1; } + try { + sl.subList(1, 0); + } catch (IllegalArgumentException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 1) + public static int test_IllegalArgument3(int execution) { + if (execution < 0 || execution > 1) { + return execution; + } + List[] lists; + try { + lists = prepareLists(); + } catch (Exception e) { + return -1; + } + + List l; + if (execution == 0) { + l = lists[0]; + } else { + l = lists[1]; + } + final List sl = asSubList(l); + final List ssl = asSubList(sl); + ssl.add(0, 42); + if (!equal(ssl.get(0), 42)) { return -1; } + if (!equal(sl.get(0), 42)) { return -1; } + if (!equal(l.get(0), 42)) { return -1; } + try { + ssl.subList(1, 0); + } catch (IllegalArgumentException e) { + return execution; + } + return -1; + } + + @Test + public static int test_Final(int execution) { + List[] lists; + try { + lists = prepareLists(); + } catch (Exception e) { + return -1; + } + + for (final List list : lists) { + if (!equalLists(list, asSubList(list))) { + return -1; + } + if (!equalLists(list, asSubList(asSubList(list)))) { + return -1; + } + } + for (int i = lists[0].size(); i > 0; i--) { + ListFrobber remover = new RandomRemover(); + for (final List list : lists) + if (!remover.frob(list)) { return -1; } + if (!equalLists(lists)) { + return -1; + } + } + return execution; + } + + /*void lockSteps(List... lists) { + for (final List list : lists) + testEmptyList(list); + for (int i = 0; i < size; i++) { + ListFrobber adder = new RandomAdder(); + for (final List list : lists) { + adder.frob(list); + equal(list.size(), i+1); + } + equalLists(lists); + } + { + final ListFrobber adder = new RandomAdder(); + final ListFrobber remover = new RandomRemover(); + for (final List list : lists) { + + THROWS(ConcurrentModificationException.class, + new F(){void f(){ + Iterator it = list.iterator(); + adder.frob(list); + it.next();}}, + new F(){void f(){ + Iterator it = asSubList(list).iterator(); + remover.frob(list); + it.next();}}, + new F(){void f(){ + Iterator it = asSubList(asSubList(list)).iterator(); + adder.frob(list); + it.next();}}, + new F(){void f(){ + List subList = asSubList(list); + remover.frob(list); + subList.get(0);}}, + new F(){void f(){ + List sl = asSubList(list); + List ssl = asSubList(sl); + adder.frob(sl); + ssl.get(0);}}, + new F(){void f(){ + List sl = asSubList(list); + List ssl = asSubList(sl); + remover.frob(sl); + ssl.get(0);}}); + } + } + + for (final List l : lists) { + final List sl = asSubList(l); + final List ssl = asSubList(sl); + ssl.add(0, 42); + equal(ssl.get(0), 42); + equal(sl.get(0), 42); + equal(l.get(0), 42); + final int s = l.size(); + final int rndIndex = rnd.nextInt(l.size()); + THROWS(IndexOutOfBoundsException.class, + new F(){void f(){l.subList(rndIndex, rndIndex).get(0);}}, + new F(){void f(){l.subList(s/2, s).get(s/2 + 1);}}, + new F(){void f(){l.subList(s/2, s).get(-1);}} + ); + THROWS(IllegalArgumentException.class, + new F(){void f(){ l.subList(1, 0);}}, + new F(){void f(){ sl.subList(1, 0);}}, + new F(){void f(){ssl.subList(1, 0);}}); + } + + equalLists(lists); + + for (final List list : lists) { + equalLists(list, asSubList(list)); + equalLists(list, asSubList(asSubList(list))); + } + for (final List list : lists) + System.out.println(list); + + for (int i = lists[0].size(); i > 0; i--) { + ListFrobber remover = randomRemover(); + for (final List list : lists) + remover.frob(list); + equalLists(lists); + } + }*/ + + static List asSubList(List list) { + return list.subList(0, list.size()); + } + + static boolean testEmptyCollection(Collection c) { + /*check(c.isEmpty()); + equal(c.size(), 0); + equal(c.toString(),"[]"); + equal(c.toArray().length, 0); + equal(c.toArray(new Object[0]).length, 0); + + Object[] a = new Object[1]; a[0] = Boolean.TRUE; + equal(c.toArray(a), a); + equal(a[0], null);*/ + if (!c.isEmpty()) { return false; } + if (!equal(c.size(), 0)) { return false; } + if (!equal(c.toString(),"[]")) { return false; } + if (!equal(c.toArray().length, 0)) { return false; } + if (!equal(c.toArray(new Object[0]).length, 0)) { return false; } + + Object[] a = new Object[1]; a[0] = Boolean.TRUE; + if (!equal(c.toArray(a), a)) { return false; } + if (!equal(a[0], null)) { return false; } + return true; + } + + static boolean testEmptyList(List list) { + if (!testEmptyCollection(list)) { + return false; + } + //equal(list, Collections.emptyList()); + return list.equals(new ArrayList()); + } + + static final Random rnd = new Random(); + + abstract static class ListFrobber { abstract boolean frob(List l); } + + static class RandomAdder extends ListFrobber { + //final Integer e = rnd.nextInt(); + final int subListCount = 1; + final boolean atBeginning = rnd.nextBoolean(); + final boolean useIterator = rnd.nextBoolean(); + @Override + boolean frob(List l) { + final int s = l.size(); + List ll = l; + for (int i = 0; i < subListCount; i++) + ll = asSubList(ll); + Integer e = l.size(); + if (!useIterator) { + if (atBeginning) { + /*switch (rnd.nextInt(3)) { + case 0: ll.add(0, e); break; + case 1: ll.subList(0, rnd.nextInt(s+1)).add(0, e); break; + case 2: ll.subList(0, rnd.nextInt(s+1)).subList(0,0).add(0,e); break; + default: throw new Error(); + }*/ + /*Integer newSymbolic = rnd.nextInt(); + if (newSymbolic == 0) { + ll.add(0, e); + } else if (newSymbolic == 1) { + ll.subList(0, rnd.nextInt(s+1)).add(0, e); + } else { + ll.subList(0, rnd.nextInt(s+1)).subList(0,0).add(0,e); + }*/ + ll.subList(0, rnd.nextInt(s+1)).subList(0,0).add(0,e); + } else { + /*switch (rnd.nextInt(3)) { + case 0: if (!ll.add(e)) { return false; } break; + case 1: ll.subList(s/2, s).add(s - s/2, e); break; + case 2: ll.subList(s, s).subList(0, 0).add(0, e); break; + default: throw new Error(); + }*/ + /*Integer newSymbolic = rnd.nextInt(); + if (newSymbolic == 0) { + if (!ll.add(e)) { return false; } + } else if (newSymbolic == 1) { + ll.subList(s/2, s).add(s - s/2, e); + } else { + ll.subList(s, s).subList(0, 0).add(0, e); + }*/ + ll.subList(s, s).subList(0, 0).add(0, e); + } + } else { + if (atBeginning) { + ListIterator it = ll.listIterator(); + if (!equal(it.nextIndex(), 0)) { return false; } + if(it.hasPrevious()) { return false; } + it.add(e); + if (!equal(it.previousIndex(), 0)) { return false; } + if (!equal(it.nextIndex(), 1)) { return false; } + if (!it.hasPrevious()) { return false; } + } else { + final int siz = ll.size(); + ListIterator it = ll.listIterator(siz); + if (!equal(it.previousIndex(), siz-1)) { return false; } + if (it.hasNext()) { return false; } + it.add(e); + if (!equal(it.previousIndex(), siz)) { return false; } + if (!equal(it.nextIndex(), siz+1)) { return false; } + if (it.hasNext()) { return false; } + if (!it.hasPrevious()) { return false; } + } + } + return true; + } + } + + /*ListFrobber randomAdder() { + final Integer e = rnd.nextInt(1024); + final int subListCount = rnd.nextInt(3); + final boolean atBeginning = rnd.nextBoolean(); + final boolean useIterator = rnd.nextBoolean(); + return new ListFrobber() {void frob(List l) { + final int s = l.size(); + List ll = l; + for (int i = 0; i < subListCount; i++) + ll = asSubList(ll); + if (! useIterator) { + if (atBeginning) { + switch (rnd.nextInt(3)) { + case 0: ll.add(0, e); break; + case 1: ll.subList(0, rnd.nextInt(s+1)).add(0, e); break; + case 2: ll.subList(0, rnd.nextInt(s+1)).subList(0,0).add(0,e); break; + default: throw new Error(); + } + } else { + switch (rnd.nextInt(3)) { + case 0: check(ll.add(e)); break; + case 1: ll.subList(s/2, s).add(s - s/2, e); break; + case 2: ll.subList(s, s).subList(0, 0).add(0, e); break; + default: throw new Error(); + } + } + } else { + if (atBeginning) { + ListIterator it = ll.listIterator(); + equal(it.nextIndex(), 0); + check(! it.hasPrevious()); + it.add(e); + equal(it.previousIndex(), 0); + equal(it.nextIndex(), 1); + check(it.hasPrevious()); + } else { + final int siz = ll.size(); + ListIterator it = ll.listIterator(siz); + equal(it.previousIndex(), siz-1); + check(! it.hasNext()); + it.add(e); + equal(it.previousIndex(), siz); + equal(it.nextIndex(), siz+1); + check(! it.hasNext()); + check(it.hasPrevious()); + } + }}}; + }*/ + + static class RandomRemover extends ListFrobber { + final int position = rnd.nextInt(3); + final int subListCount = rnd.nextInt(3); + @Override + boolean frob(List l) { + final int s = l.size(); + List ll = l; + for (int i = 0; i < subListCount; i++) + ll = asSubList(ll); + switch (position) { + case 0: // beginning + switch (rnd.nextInt(3)) { + case 0: ll.remove(0); break; + case 1: { + final Iterator it = ll.iterator(); + if (!it.hasNext()) { return false; } + /*THROWS(IllegalStateException.class, + new F(){void f(){it.remove();}});*/ + try { + it.remove(); + return false; + } catch (IllegalStateException e) {} + it.next(); + it.remove(); + /*THROWS(IllegalStateException.class, + new F(){void f(){it.remove();}});*/ + try { + it.remove(); + return false; + } catch (IllegalStateException e) {} + break;} + case 2: { + final ListIterator it = ll.listIterator(); + if (!it.hasNext()) { return false; } + /*THROWS(IllegalStateException.class, + new F(){void f(){it.remove();}});*/ + try { + it.remove(); + return false; + } catch (IllegalStateException e) {} + it.next(); + it.remove(); + /*THROWS(IllegalStateException.class, + new F(){void f(){it.remove();}});*/ + try { + it.remove(); + return false; + } catch (IllegalStateException e) {} + break;} + default: throw new Error(); + } + break; + case 1: // midpoint + switch (rnd.nextInt(3)) { + case 0: ll.remove(s/2); break; + case 1: { + final ListIterator it = ll.listIterator(s/2); + it.next(); + it.remove(); + break; + } + case 2: { + final ListIterator it = ll.listIterator(s/2+1); + it.previous(); + it.remove(); + break; + } + default: throw new Error(); + } + break; + case 2: // end + switch (rnd.nextInt(3)) { + case 0: ll.remove(s-1); break; + case 1: ll.subList(s-1, s).clear(); break; + case 2: + final ListIterator it = ll.listIterator(s); + if (it.hasNext()) { return false; } + if (!it.hasPrevious()) { return false; } + /*THROWS(IllegalStateException.class, + new F(){void f(){it.remove();}});*/ + try { + it.remove(); + return false; + } catch (IllegalStateException e) {} + it.previous(); + if (!equal(it.nextIndex(), s-1)) { return false; } + if (!it.hasNext()) { return false; } + it.remove(); + if (!equal(it.nextIndex(), s-1)) { return false; } + if (it.hasNext()) { return false; } + /*THROWS(IllegalStateException.class, + new F(){void f(){it.remove();}});*/ + try { + it.remove(); + } catch (IllegalStateException e) {} + break; + default: throw new Error(); + } + break; + default: throw new Error(); + } + return true; + } + } + + /*ListFrobber randomRemover() { + final int position = rnd.nextInt(3); + final int subListCount = rnd.nextInt(3); + return new ListFrobber() {void frob(List l) { + final int s = l.size(); + List ll = l; + for (int i = 0; i < subListCount; i++) + ll = asSubList(ll); + switch (position) { + case 0: // beginning + switch (rnd.nextInt(3)) { + case 0: ll.remove(0); break; + case 1: { + final Iterator it = ll.iterator(); + check(it.hasNext()); + THROWS(IllegalStateException.class, + new F(){void f(){it.remove();}}); + it.next(); + it.remove(); + THROWS(IllegalStateException.class, + new F(){void f(){it.remove();}}); + break;} + case 2: { + final ListIterator it = ll.listIterator(); + check(it.hasNext()); + THROWS(IllegalStateException.class, + new F(){void f(){it.remove();}}); + it.next(); + it.remove(); + THROWS(IllegalStateException.class, + new F(){void f(){it.remove();}}); + break;} + default: throw new Error(); + } + break; + case 1: // midpoint + switch (rnd.nextInt(3)) { + case 0: ll.remove(s/2); break; + case 1: { + final ListIterator it = ll.listIterator(s/2); + it.next(); + it.remove(); + break; + } + case 2: { + final ListIterator it = ll.listIterator(s/2+1); + it.previous(); + it.remove(); + break; + } + default: throw new Error(); + } + break; + case 2: // end + switch (rnd.nextInt(3)) { + case 0: ll.remove(s-1); break; + case 1: ll.subList(s-1, s).clear(); break; + case 2: + final ListIterator it = ll.listIterator(s); + check(! it.hasNext()); + check(it.hasPrevious()); + THROWS(IllegalStateException.class, + new F(){void f(){it.remove();}}); + it.previous(); + equal(it.nextIndex(), s-1); + check(it.hasNext()); + it.remove(); + equal(it.nextIndex(), s-1); + check(! it.hasNext()); + THROWS(IllegalStateException.class, + new F(){void f(){it.remove();}}); + break; + default: throw new Error(); + } + break; + default: throw new Error(); + }}}; + }*/ + + //--------------------- Infrastructure --------------------------- + /*volatile int passed = 0, failed = 0; + void pass() {passed++;} + void fail() {failed++;} + void unexpected() {failed++;} + //static void check(boolean cond) {if (cond) pass(); else fail();}*/ + static boolean equal(Object x, Object y) { + if (x == null ? y == null : x.equals(y)) { + return true; + } + else { + return false; + } + } + // void equal(T[] x, T[] y) {check(Arrays.equals(x,y));} + + /*@Test + int test_LockStep (int execution) { + try {test();} catch (Throwable t) {unexpected();} + if (failed > 0) { + return -1; + } else { + return execution; + } + } + + abstract class F {abstract void f() throws Throwable;} + static void THROWS(Class k, F... fs) { + for (F f : fs) + try {f.f(); fail();} + catch (Throwable t) { + if (k.isAssignableFrom(t.getClass())) pass(); + else unexpected();}}*/ +} diff --git a/tests/src/main/java/approximations/java/util/list/List/NestedSubListTest.java b/tests/src/main/java/approximations/java/util/list/List/NestedSubListTest.java new file mode 100644 index 00000000..fd008b4a --- /dev/null +++ b/tests/src/main/java/approximations/java/util/list/List/NestedSubListTest.java @@ -0,0 +1,56 @@ +package approximations.java.util.list.List; + +import approximations.Test; + +import java.util.*; + +@Test +public class NestedSubListTest { + static final int NEST_LIMIT = 5; + + @Test(executionMax = 2) + public static int test_AccessToSublists(int execution) { + List list; + boolean modifiable = true; + if (execution == 0) { + list = lists.get(0); + } else if (execution == 1) { + list = lists.get(1); + } else if (execution == 2) { + list = lists.get(2); + modifiable = false; + } else { + return execution; + } + for (int i = 0; i < NEST_LIMIT; ++i) { + list = list.subList(0, 1); + } + + try { + list.get(0); + if (modifiable) { + list.remove(0); + list.add(0, 42); + } + } catch (StackOverflowError e) { + return -1; + } + return execution; + } + + public static List> getLists() { + List c = new ArrayList<>(); + c.add(42); + List> lists = new LinkedList(); + lists.add(new ArrayList<>(c)); + lists.add(new LinkedList<>(c)); + lists.add(new MyList()); + return lists; + } + static final List> lists = getLists(); + + static class MyList extends AbstractList { + public Integer get(int index) { return 42; } + public int size() { return 1; } + } +} diff --git a/tests/src/main/java/approximations/java/util/list/List/SubListTest.java b/tests/src/main/java/approximations/java/util/list/List/SubListTest.java new file mode 100644 index 00000000..077a1439 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/list/List/SubListTest.java @@ -0,0 +1,1309 @@ +package approximations.java.util.list.List; + +import approximations.Test; + +import java.util.*; + +@Test +public class SubListTest { + static final Random rnd = new Random(); + + @Test(executionMax = 7) + public static int test_Add(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + List subList = list.subList(from, to); + //Integer e = rnd.nextInt(); + Integer e = 43; + subList.add(e); + if (!list.get(to).equals(e)) { + return -1; + } + if (subList.size() != to - from + 1) { + return -1; + } + return execution; + } + + @Test(executionMax = 7) + public static int test_ModAdd(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + list.add(42); + subList.add(42); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 9, disabled = true) + public static int test_UnmodAdd(int execution) { + if (execution < 0 || execution > 9) { + return execution; + } + TestCase testCase = getUnresizable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + subList.add(42); + } catch (UnsupportedOperationException e) { + return execution; + } + return -1; + } + + /*@Test(executionMax = 7) + public static int test_AddAtPos(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + List subList = list.subList(from, to); + int i = rnd.nextInt(1 + to - from); + Integer e = rnd.nextInt(); + subList.add(i, e); + if (!Objects.equals(list.get(from + i), e)) { + return -1; + } + if (subList.size() != to - from + 1) { + return -1; + } + return execution; + } + + @Test(executionMax = 7) + public static int test_ModAddAtPos(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + list.add(42); + int i = rnd.nextInt(1 + to - from); + subList.add(i, 42); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + }*/ + + @Test(executionMax = 9, disabled = true) + public static int test_UnmodAddAtPos(int execution) { + if (execution < 0 || execution > 9) { + return execution; + } + TestCase testCase = getUnresizable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + int i = rnd.nextInt(1 + to - from); + subList.add(i, 42); + } catch (UnsupportedOperationException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 7) + public static int test_Clear(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + List subList = list.subList(from, to); + subList.clear(); + if (!subList.isEmpty()) { + return -1; + } + if (subList.size() != 0) { + return -1; + } + return execution; + } + + @Test(executionMax = 7) + public static int test_ModClear(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + list.add(42); + subList.clear(); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 9, disabled = true) + public static int test_UnmodClear(int execution) { + if (execution < 0 || execution > 9) { + return execution; + } + TestCase testCase = getUnresizable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + subList.clear(); + } catch (UnsupportedOperationException e) { + return execution; + } + return -1; + } + + /*@Test(executionMax = 17) + public static int test_Equals(int execution) { + if (execution < 0 || execution > 17) { + return execution; + } + TestCase testCase = getAll(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + List subList1 = list.subList(from, to); + List subList2 = list.subList(from, to); + if (!subList1.equals(subList2)) { + return -1; + } + for (int i = 0; i != 16; ++i) { + int from3 = rnd.nextInt(1 + list.size()); + int to3 = from3 + rnd.nextInt(1 + list.size() - from3); + boolean equal = (to - from) == (to3 - from3); + for (int j = 0; j < to - from && j < to3 - from3; ++j) + equal &= Objects.equals(list.get(from + j), list.get(from3 + j)); + List subList3 = list.subList(from3, to3); + if (subList1.equals(subList3) != equal) { + return -1; + } + } + return execution; + }*/ + +// @Test(dataProvider = "modifiable", +// expectedExceptions = ConcurrentModificationException.class) +// public void testModEquals(List list, int from, int to) { +// List subList = list.subList(from, to); +// list.add(42); +// subList.equals(subList); +// } + + @Test(executionMax = 7) + public static int test_ModHashCode(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + list.add(42); + subList.hashCode(); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 17) + public static int test_Get(int execution) { + if (execution < 0 || execution > 17) { + return execution; + } + TestCase testCase = getAll(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + List subList = list.subList(from, to); + for (int i = 0; i < to - from; ++i) { + if (!Objects.equals(list.get(from + i), subList.get(i))) { + return -1; + } + } + return execution; + } + + @Test(executionMax = 7) + public static int test_ModGet(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + list.add(42); + subList.get(from); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + } + + /*@Test(executionMax = 17) + public static int test_IndexOf(int execution) { + if (execution < 0 || execution > 17) { + return execution; + } + TestCase testCase = getAll(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + List subList = list.subList(from, to); + if (from < to) { + Integer e = list.get(from); + int j = subList.indexOf(e); + if (j != 0) { + return -1; + } + } + for (int i = 0; i < list.size(); ++i) { + Integer e = list.get(i); + int j = subList.indexOf(e); + if (i < from || i >= to) { + if (!(j == -1 || Objects.equals(subList.get(j), e))) { + return -1; + } + } else { + if (j < 0) { + return -1; + } + if (j > i - from) { + return -1; + } + if (!Objects.equals(subList.get(j), e)) { + return -1; + } + } + } + for (int i = 0; i < 16; ++i) { + Integer r = rnd.nextInt(); + if (list.contains(r)) continue; + int j = subList.indexOf(r); + if (j != -1) { + return -1; + } + } + return execution; + }*/ + + @Test(executionMax = 7) + public static int test_ModIndexOf(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + list.add(42); + subList.indexOf(from); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 17) + public static int test_Iterator(int execution) { + if (execution < 0 || execution > 17) { + return execution; + } + TestCase testCase = getAll(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + List subList = list.subList(from, to); + Iterator it = subList.iterator(); + for (int i = from; i < to; ++i) { + if (!it.hasNext()) { + return -1; + } + if (!Objects.equals(list.get(i), it.next())) { + return -1; + } + } + if (it.hasNext()) { + return -1; + } + return execution; + } + + @Test(executionMax = 7) + public static int test_ModIteratorNext(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + Iterator it = subList.iterator(); + list.add(42); + it.next(); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 7) + public static int test_IteratorRemove(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + //List c1 = new ArrayList<>(); + //c1.add(42); + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + List subList = list.subList(from, to); + Iterator it = subList.iterator(); + for (int i = from; i < to; ++i) { + if (!it.hasNext()) { + return -1; + } + if (!Objects.equals(list.get(from), it.next())) { + return -1; + } + it.remove(); + } + if (it.hasNext()) { + return -1; + } + if (!subList.isEmpty()) { + return -1; + } + return execution; + } + + @Test(executionMax = 7) + public static int test_ModIteratorRemove(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + Iterator it = subList.iterator(); + it.next(); + list.add(42); + it.remove(); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 9, disabled = true) + public static int test_UnmodIteratorRemove(int execution) { + if (execution < 0 || execution > 9) { + return execution; + } + TestCase testCase = getUnresizable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + Iterator it = subList.iterator(); + it.next(); + it.remove(); + } catch (UnsupportedOperationException e) { + return execution; + } + return -1; + } + + /*@Test(executionMax = 17) + public static int test_IteratorForEachRemaining(int execution) { + if (execution < 0 || execution > 17) { + return execution; + } + TestCase testCase = getAll(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + List subList = list.subList(from, to); + for (int k = 0; k < 16; ++k) { + int r = from + rnd.nextInt(1 + to - from); + Iterator it = subList.iterator(); + for (int i = from; i < to; ++i) { + if (!it.hasNext()) { + return -1; + } + if (i == r) { + Iterator jt = list.listIterator(r); + while (it.hasNext()) { + if (!(jt.hasNext() && Objects.equals(it.next(), jt.next()))) { + return -1; + } + } + break; + } + if (!Objects.equals(list.get(i), it.next())) { + return -1; + } + } + if (it.hasNext()) { + return -1; + } + } + return execution; + } + + @Test(executionMax = 17) + public static int test_LastIndexOf(int execution) { + if (execution < 0 || execution > 17) { + return execution; + } + TestCase testCase = getAll(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + List subList = list.subList(from, to); + if (from < to) { + Integer e = list.get(to - 1); + int j = subList.lastIndexOf(e); + if (j != to - from - 1) { + return -1; + } + } + for (int i = 0; i < list.size(); ++i) { + Integer e = list.get(i); + int j = subList.lastIndexOf(e); + if (i < from || i >= to) { + if (!(j == -1 || Objects.equals(subList.get(j), e))) { + return -1; + } + } else { + if (!(j >= 0 && j >= i - from)) { + return -1; + } + if (!Objects.equals(subList.get(j), e)) { + return -1; + } + } + } + for (int i = 0; i < 16; ++i) { + Integer r = rnd.nextInt(); + if (list.contains(r)) continue; + int j = subList.lastIndexOf(r); + if (j != -1) { + return -1; + } + } + return execution; + }*/ + + @Test(executionMax = 7) + public static int test_ModLastIndexOf(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + list.add(42); + subList.lastIndexOf(42); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 9) + public static int test_ListIterator(int execution) { + if (execution < 0 || execution > 9) { + return execution; + } + TestCase testCase = getUnresizable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + List subList = list.subList(from, to); + ListIterator it = subList.listIterator(); + for (int i = from; i < to; ++i) { + if (!it.hasNext()) { + return -1; + } + if (it.nextIndex() != i - from) { + return -1; + } + if (!Objects.equals(list.get(i), it.next())) { + return -1; + } + } + if (it.hasNext()) { + return -1; + } + return execution; + } + + @Test(executionMax = 7) + public static int test_ModListIteratorNext(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + ListIterator it = subList.listIterator(); + list.add(42); + it.next(); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + } + + /*@Test(executionMax = 7) + public static int test_ListIteratorSet(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + List subList = list.subList(from, to); + ListIterator it = subList.listIterator(); + for (int i = from; i < to; ++i) { + if (!it.hasNext()) { + return -1; + } + if (it.nextIndex() != i - from) { + return -1; + } + if (!Objects.equals(list.get(i), it.next())) { + return -1; + } + Integer e = rnd.nextInt(); + it.set(e); + if (!Objects.equals(list.get(i), e)) { + return -1; + } + } + if (it.hasNext()) { + return -1; + } + return execution; + }*/ + + @Test(executionMax = 7) + public static int test_ModListIteratorSet(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + ListIterator it = subList.listIterator(); + it.next(); + list.add(42); + it.set(42); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 3) + public static int test_UnmodListIteratorSet(int execution) { + if (execution < 0 || execution > 3) { + return execution; + } + TestCase testCase = getUnsettable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + ListIterator it = subList.listIterator(); + it.next(); + it.set(42); + } catch (UnsupportedOperationException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 9) + public static int test_ListIteratorPrevious(int execution) { + if (execution < 0 || execution > 9) { + return execution; + } + TestCase testCase = getUnresizable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + List subList = list.subList(from, to); + ListIterator it = subList.listIterator(subList.size()); + for (int i = to - 1; i >= from; --i) { + if (!it.hasPrevious()) { + return -1; + } + if (it.previousIndex() != i - from) { + return -1; + } + if (!Objects.equals(list.get(i), it.previous())) { + return -1; + } + } + if (it.hasPrevious()) { + return -1; + } + return execution; + } + + @Test(executionMax = 7) + public static int test_ModListIteratorPrevious(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + ListIterator it = subList.listIterator(to - from); + list.add(42); + it.previous(); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + } + + /*@Test(executionMax = 7) + public static int test_ListIteratorSetPrevious(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + List subList = list.subList(from, to); + ListIterator it = subList.listIterator(subList.size()); + for (int i = to - 1; i >= from; --i) { + if (!it.hasPrevious()) { + return -1; + } + if (it.previousIndex() != i - from) { + return -1; + } + if (!Objects.equals(list.get(i), it.previous())) { + return -1; + } + Integer e = rnd.nextInt(); + it.set(e); + if (!Objects.equals(list.get(i), e)) { + return -1; + } + } + if (it.hasPrevious()) { + return -1; + } + return execution; + }*/ + + @Test(executionMax = 3) + public static int test_UnmodListIteratorSetPrevious(int execution) { + if (execution < 0 || execution > 3) { + return execution; + } + TestCase testCase = getUnsettable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + ListIterator it = subList.listIterator(to - from); + it.previous(); + it.set(42); + } catch (UnsupportedOperationException e) { + return execution; + } + return -1; + } + + /*@Test(executionMax = 7) + public static int test_ListIteratorAdd(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + List subList = list.subList(from, to); + for (int i = 0; i < 16; ++i) { + int r = rnd.nextInt(1 + subList.size()); + ListIterator it = subList.listIterator(r); + Integer e = rnd.nextInt(); + it.add(e); + if (!Objects.equals(it.previous(), e)) { + return -1; + } + if (!Objects.equals(list.get(from + r), e)) { + return -1; + } + } + return execution; + }*/ + + @Test(executionMax = 9, disabled = true) + public static int test_UnmodListIteratorAdd(int execution) { + if (execution < 0 || execution > 9) { + return execution; + } + TestCase testCase = getUnresizable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + int r = rnd.nextInt(1 + subList.size()); + ListIterator it = subList.listIterator(r); + it.add(42); + } catch (UnsupportedOperationException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 7) + public static int test_ModListIteratorAdd(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + ListIterator it = subList.listIterator(); + it.next(); + list.add(42); + it.add(42); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 7) + public static int test_ListIteratorRemoveNext(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + List subList = list.subList(from, to); + ListIterator it = subList.listIterator(); + for (int i = from; i < to; ++i) { + if (!it.hasNext()) { + return -1; + } + if (it.nextIndex() != 0) { + return -1; + } + if (!Objects.equals(list.get(from), it.next())) { + return -1; + } + it.remove(); + } + if (it.hasNext()) { + return -1; + } + if (!subList.isEmpty()) { + return -1; + } + return execution; + } + + @Test(executionMax = 9, disabled = true) + public static int test_UnmodListIteratorRemoveNext(int execution) { + if (execution < 0 || execution > 9) { + return execution; + } + TestCase testCase = getUnresizable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + ListIterator it = subList.listIterator(); + it.next(); + it.remove(); + } catch (UnsupportedOperationException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 7) + public static int test_ModListIteratorRemove(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + ListIterator it = subList.listIterator(); + it.next(); + list.add(42); + it.remove(); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 7) + public static int test_ListIteratorRemovePrevious(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + List subList = list.subList(from, to); + ListIterator it = subList.listIterator(subList.size()); + for (int i = to - 1; i >= from; --i) { + if (!it.hasPrevious()) { + return -1; + } + if (it.previousIndex() != i - from) { + return -1; + } + if (!Objects.equals(list.get(i), it.previous())) { + return -1; + } + it.remove(); + } + if (it.hasPrevious()) { + return -1; + } + if (!subList.isEmpty()) { + return -1; + } + return execution; + } + + @Test(executionMax = 9, disabled = true) + public static int test_UnmodListIteratorRemovePrevious(int execution) { + if (execution < 0 || execution > 9) { + return execution; + } + TestCase testCase = getUnresizable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + ListIterator it = subList.listIterator(subList.size()); + it.previous(); + it.remove(); + } catch (UnsupportedOperationException e) { + return execution; + } + return -1; + } + + /*@Test(executionMax = 7) + public static int test_Remove(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + List subList = list.subList(from, to); + for (int i = 0; i < 16; ++i) { + if (subList.isEmpty()) break; + int r = rnd.nextInt(subList.size()); + Integer e = list.get(from + r); + if (!Objects.equals(subList.remove(r), e)) { + return -1; + } + } + return execution; + }*/ + + @Test(executionMax = 9, disabled = true) + public static int test_UnmodRemove(int execution) { + if (execution < 0 || execution > 9) { + return execution; + } + TestCase testCase = getUnresizable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + int r = rnd.nextInt(subList.size()); + subList.remove(r); + } catch (UnsupportedOperationException e) { + return execution; + } + return -1; + } + + @Test(executionMax = 7) + public static int test_ModRemove(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + list.add(42); + subList.remove(0); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + } + + /*@Test(executionMax = 7) + public static int test_Set(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + List subList = list.subList(from, to); + for (int i = 0; i < to - from; ++i) { + Integer e0 = list.get(from + i); + Integer e1 = rnd.nextInt(); + if (!Objects.equals(subList.set(i, e1), e0)) { + return -1; + } + if (!Objects.equals(list.get(from + i), e1)) { + return -1; + } + } + return execution; + }*/ + + @Test(executionMax = 7) + public static int test_ModSet(int execution) { + if (execution < 0 || execution > 7) { + return execution; + } + TestCase testCase = getModifiable(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + try { + List subList = list.subList(from, to); + list.add(42); + subList.set(0, 42); + } catch (ConcurrentModificationException e) { + return execution; + } + return -1; + } + + @Test + public static int test_SubListEquals(int execution) { + List list1 = new ArrayList<>(); + List list2 = new ArrayList<>(); + for (int i = 1; i < 5; i++) { + list1.add(i); + } + for (int i = 2; i < 6; i++) { + list2.add(i); + } + List sublist1 = list1.subList(1, 4); + List sublist2 = list2.subList(0, 3); + if (sublist1.equals(sublist2)) { + return execution; + } else { + return -1; + } + } + + /*@Test(executionMax = 17) + public static int test_SubList(int execution) { + if (execution < 0 || execution > 17) { + return execution; + } + TestCase testCase = getAll(execution); + List list = testCase.list; + Integer from = testCase.from; + Integer to = testCase.to; + List subList = list.subList(from, to); + for (int i = 0; i < 16 && from < to; ++i) { + int from1 = rnd.nextInt(to - from); + int to1 = from1 + 1 + rnd.nextInt(to - from - from1); + List subSubList = subList.subList(from1, to1); + for (int j = 0; j < to1 - from1; ++j) { + if (!Objects.equals(list.get(from + from1 + j), subSubList.get(j))) { + return -1; + } + } + } + return execution; + }*/ + + /** + * All kinds of lists + */ + + static class TestCase { + List list; + Integer from, to; + TestCase(List _list, Integer _from, Integer _to) { + list = _list; + from = _from; + to = _to; + } + } + + public static TestCase getAll(int execution) { + /*TestCase[] l1 = getModifiable(); + TestCase[] l2 = getUnresizable(); + TestCase[] res = Arrays.copyOf(l1, l1.length + l2.length); + System.arraycopy(l2, 0, res, l1.length, l2.length); + return res;*/ + Integer[] c9_copy = new Integer[] { 40, 41, 42, 43, 44, 45, -1, + Integer.MIN_VALUE, 1000500 }; + List c1 = new ArrayList<>(); + c1.add(42); + List c9 = new ArrayList<>(); + for (Integer it : c9_copy) { + c9.add(it); + } + if (execution == 0) { + return new TestCase(new ArrayList<>(c1), 0, 1); + } else if (execution == 1) { + return new TestCase(new LinkedList<>(c1), 0, 1); + } else if (execution == 2) { + return new TestCase(new ArrayList<>(c1).subList(0, 1), 0, 1); + } else if (execution == 3) { + return new TestCase(new LinkedList<>(c1).subList(0, 1), 0, 1); + } else if (execution == 4) { + return new TestCase(new ArrayList<>(c9), 2, 5); + } else if (execution == 5) { + return new TestCase(new LinkedList<>(c9), 2, 5); + } else if (execution == 6) { + return new TestCase(new ArrayList<>(c9).subList(1, 8), 1, 4); + } else if (execution == 7) { + return new TestCase(new LinkedList<>(c9).subList(1, 8), 1, 4); + } else if (execution == 8) { + return new TestCase(new MyList(1), 0, 1); + } else if (execution == 9) { + return new TestCase(new MyList(1).subList(0, 1), 0, 1); + } else if (execution == 10) { + return new TestCase(new MyList(9), 3, 6); + } else if (execution == 11) { + return new TestCase(new MyList(9).subList(2, 8), 3, 6); + } else if (execution == 12) { + return new TestCase(c1, 0, 1); + } else if (execution == 13) { + return new TestCase(c1.subList(0, 1), 0, 1); + } else if (execution == 14) { + return new TestCase(c9, 0, 4); + } else if (execution == 15) { + return new TestCase(c9, 4, 6); + } else if (execution == 16) { + return new TestCase(c9.subList(1, 8), 1, 4); + } else { + return new TestCase(c9.subList(1, 8), 0, 7); + } + } + //static final TestCase[] all = getAll(); + + /** + * Lists that allow any modifications: resizing and setting values + */ + public static TestCase getModifiable(int execution) { + Integer[] c9_copy = new Integer[] { 40, 41, 42, 43, 44, 45, -1, + Integer.MIN_VALUE, 1000500 }; + List c1 = new ArrayList<>(); + c1.add(42); + List c9 = new ArrayList<>(); + for (Integer it : c9_copy) { + c9.add(it); + } + + /*return new TestCase[] { + new TestCase(new ArrayList<>(c1), 0, 1), + new TestCase(new LinkedList<>(c1), 0, 1), + new TestCase(new ArrayList<>(c1).subList(0, 1), 0, 1), + new TestCase(new LinkedList<>(c1).subList(0, 1), 0, 1), + new TestCase(new ArrayList<>(c9), 2, 5), + new TestCase(new LinkedList<>(c9), 2, 5), + new TestCase(new ArrayList<>(c9).subList(1, 8), 1, 4), + new TestCase(new LinkedList<>(c9).subList(1, 8), 1, 4) + };*/ + if (execution == 0) { + return new TestCase(new ArrayList<>(c1), 0, 1); + } else if (execution == 1) { + return new TestCase(new LinkedList<>(c1), 0, 1); + } else if (execution == 2) { + return new TestCase(new ArrayList<>(c1).subList(0, 1), 0, 1); + } else if (execution == 3) { + return new TestCase(new LinkedList<>(c1).subList(0, 1), 0, 1); + } else if (execution == 4) { + return new TestCase(new ArrayList<>(c9), 2, 5); + } else if (execution == 5) { + return new TestCase(new LinkedList<>(c9), 2, 5); + } else if (execution == 6) { + return new TestCase(new ArrayList<>(c9).subList(1, 8), 1, 4); + } else { + return new TestCase(new LinkedList<>(c9).subList(1, 8), 1, 4); + } + } + //static final TestCase[] modifiable = getModifiable(); + + /** + * Lists that don't allow resizing, but allow setting values + */ + public static TestCase getUnresizable(int execution) { + Integer[] c9_copy = new Integer[] { 40, 41, 42, 43, 44, 45, -1, + Integer.MIN_VALUE, 1000500 }; + List c1 = new ArrayList<>(); + c1.add(42); + List c9 = new ArrayList<>(); + for (Integer it : c9_copy) { + c9.add(it); + } + + /*TestCase[] l1 = getUnsettable(); + TestCase[] l2 = { + new TestCase(c1, 0, 1), + new TestCase(c1.subList(0, 1), 0, 1), + new TestCase(c9, 0, 4), + new TestCase(c9, 4, 6), + new TestCase(c9.subList(1, 8), 1, 4), + new TestCase(c9.subList(1, 8), 0, 7), + }; + TestCase[] res = Arrays.copyOf(l1, l1.length + l2.length); + System.arraycopy(l2, 0, res, l1.length, l2.length); + return res;*/ + + if (execution == 0) { + return new TestCase(new MyList(1), 0, 1); + } else if (execution == 1) { + return new TestCase(new MyList(1).subList(0, 1), 0, 1); + } else if (execution == 2) { + return new TestCase(new MyList(9), 3, 6); + } else if (execution == 3) { + return new TestCase(new MyList(9).subList(2, 8), 3, 6); + } else if (execution == 4) { + return new TestCase(c1, 0, 1); + } else if (execution == 5) { + return new TestCase(c1.subList(0, 1), 0, 1); + } else if (execution == 6) { + return new TestCase(c9, 0, 4); + } else if (execution == 7) { + return new TestCase(c9, 4, 6); + } else if (execution == 8) { + return new TestCase(c9.subList(1, 8), 1, 4); + } else { + return new TestCase(c9.subList(1, 8), 0, 7); + } + } + //static final TestCase[] unresizable = getUnresizable(); + + /** + * Lists that don't allow either resizing or setting values + */ + public static TestCase getUnsettable(int execution) { + /*return new TestCase[] { + new TestCase(new MyList(1), 0, 1), + new TestCase(new MyList(1).subList(0, 1), 0, 1), + new TestCase(new MyList(9), 3, 6), + new TestCase(new MyList(9).subList(2, 8), 3, 6) + };*/ + if (execution == 0) { + return new TestCase(new MyList(1), 0, 1); + } else if (execution == 1) { + return new TestCase(new MyList(1).subList(0, 1), 0, 1); + } else if (execution == 2) { + return new TestCase(new MyList(9), 3, 6); + } else { + return new TestCase(new MyList(9).subList(2, 8), 3, 6); + } + } + //static final TestCase[] unsettable = getUnsettable(); + + static class MyList extends AbstractList { + private final int size; + MyList(int s) { size = s; } + public Integer get(int index) { return 42; } + public int size() { return size; } + } +} diff --git a/tests/src/main/java/approximations/java/util/map/AbstractMap/AbstractMapCloneTest.java b/tests/src/main/java/approximations/java/util/map/AbstractMap/AbstractMapCloneTest.java new file mode 100644 index 00000000..d4349dea --- /dev/null +++ b/tests/src/main/java/approximations/java/util/map/AbstractMap/AbstractMapCloneTest.java @@ -0,0 +1,72 @@ +package approximations.java.util.map.AbstractMap; + +import approximations.Test; + +import java.util.AbstractMap; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +@Test +public class AbstractMapCloneTest extends AbstractMap implements Cloneable { + private Map map = new HashMap(); + + public Set entrySet() { + return map.entrySet(); + } + + public Object put(Object key, Object value) { + return map.put(key, value); + } + + public Object clone() { + final AbstractMapCloneTest clone; + try { + clone = (AbstractMapCloneTest)super.clone(); + } catch (CloneNotSupportedException e) { + throw new AssertionError(e); + } + clone.map = (Map)((HashMap)map).clone(); + return clone; + } + + public int size() { + return map.size(); + } + + public Set keySet() { + return map.keySet(); + } + + @Test + public static int test_abstractMapClone(int execution) { + AbstractMapCloneTest m1 = new AbstractMapCloneTest(); + m1.put("1", "1"); + Set k1 = m1.keySet(); + AbstractMapCloneTest m2 = (AbstractMapCloneTest)m1.clone(); + Set k2 = m2.keySet(); + m2.put("2","2"); + if (k1.equals(k2)) { + return -1; + } + if (m2.size() != 2) { + return -1; + } + return execution; + } + + @Test + public static int test_hashMapClone(int execution) { + Map m1 = new HashMap<>(); + m1.put(1, 1); + Set k1 = m1.keySet(); + Map m2 = (Map) ((HashMap) m1).clone(); + Set k2 = m2.keySet(); + m2.put(2, 2); + if (k1.equals(k2)) { + return -1; + } else { + return execution; + } + } +} diff --git a/tests/src/main/java/approximations/java/util/map/AbstractMap/EqualsTest.java b/tests/src/main/java/approximations/java/util/map/AbstractMap/EqualsTest.java new file mode 100644 index 00000000..6d5b0075 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/map/AbstractMap/EqualsTest.java @@ -0,0 +1,33 @@ +package approximations.java.util.map.AbstractMap; + +import approximations.Test; + +import java.util.*; + +@Test +public class EqualsTest { + @Test + public static int test_equalsTest(int execution) { + Map m = new HashMap(); + m.put(null, ""); + Map h = new Hashtable(); + h.put("", ""); + if (m.equals(h)) + return -1; + + Map m1 = new TreeMap(); + m1.put(42, "The Answer"); + Map m2 = new TreeMap(); + m2.put("The Answer", 42); + if (m1.equals(m2)) + return -1; + + Set s1 = new TreeSet(); + s1.add(666); + Set s2 = new TreeSet(); + s2.add("Great googly moogly!"); + if (s1.equals(s2)) + return -1; + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/map/AbstractMap/MapEntriesTest.java b/tests/src/main/java/approximations/java/util/map/AbstractMap/MapEntriesTest.java new file mode 100644 index 00000000..fa265bfc --- /dev/null +++ b/tests/src/main/java/approximations/java/util/map/AbstractMap/MapEntriesTest.java @@ -0,0 +1,97 @@ +package approximations.java.util.map.AbstractMap; + +import approximations.Test; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +@Test +public class MapEntriesTest { + private static int testEntry(Map.Entry e) { + String k = "foo"; + Long v = 1L; + Long v2 = 2L; + /*if (!equal(e.getKey(), k)) { + return -1; + } + if (!equal(e.getValue(), v)) { + return -1; + } + Map mapWithSameEntry = new LinkedHashMap<>(); + mapWithSameEntry.put(k, v); + if (!equal(e, mapWithSameEntry.entrySet().iterator().next())) { + return -1; + }*/ + Map mapWithAnotherEntry = new LinkedHashMap<>(); + mapWithAnotherEntry.put(k, v2); + if (e.equals(mapWithAnotherEntry.entrySet().iterator().next())) { + return -1; + } + /*if (e.equals(null)) { + return -1; + }*/ + String test = k + "=" + v; + /*if (!equal(e.toString(), k+"="+v)) { + return -1; + } + if (!equal(e.setValue(v2), v)) { + return -1; + } + if (!equal(e.getValue(), v2)) { + return -1; + } + if (!equal(e.setValue(null), v2)) { + return -1; + } + if (!equal(e.getValue(), null)) { + return -1; + }*/ + return 0; + } + + private static int testNullEntry(Map.Entry e) { + Long v = 1L; + if (!equal(e.getKey(), null)) { + return -1; + } + if (!equal(e.getValue(), null)) { + return -1; + } + Map mapWithSameEntry = new LinkedHashMap<>(); + mapWithSameEntry.put(null, null); + if (!equal(e, mapWithSameEntry.entrySet().iterator().next())) { + return -1; + } + if (!equal(e.toString(), "null=null")) { + return -1; + } + if (!equal(e.setValue(v), null)) { + return -1; + } + if (!equal(e.getValue(), v)) { + return -1; + } + return 0; + } + + static boolean equal(Object x, Object y) { + if (x == null ? y == null : x.equals(y)) return true; + else return false;} + + @Test + public static int test_ConcreteEntry(int execution) { + String k = "foo"; + Long v = 1L; + Map map = new HashMap<>(); + map.put(k, v); + return testEntry(map.entrySet().iterator().next()); + } + + @Test + public static int test_NullEntry(int execution) { + Map map = new LinkedHashMap<>(); + map.put(null, null); + return testNullEntry(map.entrySet().iterator().next()); + } +} diff --git a/tests/src/main/java/approximations/java/util/map/AbstractMap/NullAsKeyTest.java b/tests/src/main/java/approximations/java/util/map/AbstractMap/NullAsKeyTest.java new file mode 100644 index 00000000..2cca6658 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/map/AbstractMap/NullAsKeyTest.java @@ -0,0 +1,16 @@ +package approximations.java.util.map.AbstractMap; + +import approximations.Test; + +import java.util.HashMap; +import java.util.Map; + +@Test +public class NullAsKeyTest { + @Test + static int test_NullAsKey(int execution) { + Map m = new HashMap(); + m.put(null, ""); + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/map/AbstractMap/ToStringTest.java b/tests/src/main/java/approximations/java/util/map/AbstractMap/ToStringTest.java new file mode 100644 index 00000000..45aaa76e --- /dev/null +++ b/tests/src/main/java/approximations/java/util/map/AbstractMap/ToStringTest.java @@ -0,0 +1,32 @@ +package approximations.java.util.map.AbstractMap; + +import approximations.Test; + +import java.util.LinkedHashMap; +import java.util.Map; + +@Test +public class ToStringTest { + @Test + public static int test_toString(int execution) { + Map m = new LyingMap(); + if (!m.toString().equals("{}")) + return -1; + + m.put("x", "1"); + if (!m.toString().equals("{x=1}")) + return -1; + + m.put("y", "2"); + String toStringResult = m.toString(); + if (!toStringResult.equals("{x=1, y=2}") && !toStringResult.equals("{y=2, x=1}")) + return -1; + return execution; + } +} + +class LyingMap extends LinkedHashMap { + public int size() { + return super.size() + 1; // Lies, lies, all lies! + } +} diff --git a/tests/src/main/java/approximations/java/util/map/HashMap/HashMapCloneLeakTest.java b/tests/src/main/java/approximations/java/util/map/HashMap/HashMapCloneLeakTest.java new file mode 100644 index 00000000..3d08c5d3 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/map/HashMap/HashMapCloneLeakTest.java @@ -0,0 +1,28 @@ +package approximations.java.util.map.HashMap; + +import approximations.Test; + +import java.lang.ref.WeakReference; +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +@Test +public class HashMapCloneLeakTest { + + @Test + public static int test_HashMapCloneLeak(int execution) { + int size = 2; + Random random = new Random(777); + Map map1 = new HashMap<>(); + for (int i = 0; i < size; i++) { + map1.put(random.nextInt(), random.nextInt()); + } + + Map map2 = (Map) ((HashMap) map1).clone(); + if (!map1.equals(map2)) { + return -1; + } + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/map/HashMap/KeySetRemoveTest.java b/tests/src/main/java/approximations/java/util/map/HashMap/KeySetRemoveTest.java new file mode 100644 index 00000000..b7c6c75a --- /dev/null +++ b/tests/src/main/java/approximations/java/util/map/HashMap/KeySetRemoveTest.java @@ -0,0 +1,21 @@ +package approximations.java.util.map.HashMap; + +import approximations.Test; + +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; + +@Test +public class KeySetRemoveTest { + @Test + public static int test_KeySetRemove(int execution) { + Map[] m = {new HashMap()}; + for (int i=0; i old_order = new ArrayList<>(); + Map m = new HashMap<>(16); + int number = 0; + while(number < 100000) { + m.put(null,null); + m.remove(null); + Integer adding = (number += 100); + m.put(adding, null); + List new_order = new ArrayList<>(); + new_order.addAll(m.keySet()); + new_order.remove(adding); + if(!old_order.equals(new_order)) { + break; + } + old_order.clear(); + old_order.addAll(m.keySet()); + } + if(number == 100000) { + return -1; + } + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/map/HashMap/OverrideIsEmptyTest.java b/tests/src/main/java/approximations/java/util/map/HashMap/OverrideIsEmptyTest.java new file mode 100644 index 00000000..2dfd2ef6 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/map/HashMap/OverrideIsEmptyTest.java @@ -0,0 +1,48 @@ +package approximations.java.util.map.HashMap; + +import approximations.Test; + +import java.util.HashMap; + +@Test +public class OverrideIsEmptyTest { + public static class NotEmptyHashMap extends HashMap { + private K alwaysExistingKey; + private V alwaysExistingValue; + + @Override + public V get(Object key) { + if (key == alwaysExistingKey) { + return alwaysExistingValue; + } + return super.get(key); + } + + @Override + public int size() { + return super.size() + 1; + } + + @Override + public boolean isEmpty() { + return size() == 0; + } + } + + @Test + public static int test_OverrideIsEmpty (int execution) { + try { + NotEmptyHashMap map = new NotEmptyHashMap<>(); + Object key = new Object(); + Object value = new Object(); + map.get(key); + map.remove(key); + map.replace(key, value, null); + map.replace(key, value); + map.computeIfPresent(key, (key1, oldValue) -> oldValue); + } catch (Throwable t) { + return -1; + } + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/map/HashMap/PutNullKeyTest.java b/tests/src/main/java/approximations/java/util/map/HashMap/PutNullKeyTest.java new file mode 100644 index 00000000..447b3d55 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/map/HashMap/PutNullKeyTest.java @@ -0,0 +1,59 @@ +package approximations.java.util.map.HashMap; + +import approximations.Test; + +import java.util.HashMap; +import java.util.Map; + +@Test +public class PutNullKeyTest { + static final int INITIAL_CAPACITY = 5; + + static final int SIZE = 10; + + static final float LOAD_FACTOR = 1.0f; + + public static class CollidingHash implements Comparable { + + private final int value; + + public CollidingHash(int value) { + this.value = value; + } + + @Override + public int hashCode() { + return 0; + } + + @Override + public boolean equals(Object o) { + if (null == o) { + return false; + } + + if (o.getClass() != CollidingHash.class) { + return false; + } + + return value == ((CollidingHash) o).value; + } + + @Override + public int compareTo(CollidingHash o) { + return value - o.value; + } + } + + @Test + public static int test_PutNullKey(int execution) { + Map m = new HashMap<>(INITIAL_CAPACITY, LOAD_FACTOR); + for (int i = 0; i < SIZE; i++) { + CollidingHash newHash = new CollidingHash(i); + m.put(newHash, newHash); + } + + m.put(null, null); + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/map/HashMap/ReplaceExistingTest.java b/tests/src/main/java/approximations/java/util/map/HashMap/ReplaceExistingTest.java new file mode 100644 index 00000000..a10b8b00 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/map/HashMap/ReplaceExistingTest.java @@ -0,0 +1,55 @@ +package approximations.java.util.map.HashMap; + +import approximations.Test; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; + +@Test +public class ReplaceExistingTest { + private static int STATIC = 13; + + @Test + // TODO: fix interning Integer approximation + public static int test_ReplaceExisting(int execution) { + int ENTRIES = 13; + for (int i = 0; i <= 0; i++) { + HashMap hm = new HashMap<>(16, 0.75f); + for (int j = 0; j < ENTRIES; j++) { + hm.put(j*10, j*10); + } + if (i > hm.size()) { + return -1; + } + HashSet keys = new HashSet<>(hm.size()); + keys.addAll(hm.keySet()); + + HashSet collected = new HashSet<>(hm.size()); + + Iterator itr = hm.keySet().iterator(); + for (int j = 0; j < i; j++) { + Integer retVal = itr.next(); + if (!collected.add(retVal)) { + return -1; + } + } + + if (null == hm.put(0, 100)) { + return -1; + } + + while(itr.hasNext()) { + Integer retVal = itr.next(); + if (!collected.add(retVal)) { + return -1; + } + } + + if (!keys.equals(collected)) { + return -1; + } + } + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/map/HashMap/SetValueTest.java b/tests/src/main/java/approximations/java/util/map/HashMap/SetValueTest.java new file mode 100644 index 00000000..3cc31d9b --- /dev/null +++ b/tests/src/main/java/approximations/java/util/map/HashMap/SetValueTest.java @@ -0,0 +1,24 @@ +package approximations.java.util.map.HashMap; + +import approximations.Test; + +import java.util.Map; +import java.util.HashMap; + +@Test +public class SetValueTest { + static final String key = "key"; + static final String oldValue = "old"; + static final String newValue = "new"; + + @Test + public static int test_SetValue(int execution) { + Map m = new HashMap(); + m.put(key, oldValue); + Map.Entry e = (Map.Entry) m.entrySet().iterator().next(); + Object returnVal = e.setValue(newValue); + if (!returnVal.equals(oldValue)) + return -1; + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/map/HashMap/ToArrayTest.java b/tests/src/main/java/approximations/java/util/map/HashMap/ToArrayTest.java new file mode 100644 index 00000000..3864fb4e --- /dev/null +++ b/tests/src/main/java/approximations/java/util/map/HashMap/ToArrayTest.java @@ -0,0 +1,172 @@ +package approximations.java.util.map.HashMap; + +import approximations.Test; + +import java.util.*; +import java.util.stream.LongStream; + +@Test +public class ToArrayTest { + public static int mismatch(Object[] a, Object[] b) { + int length = Math.min(a.length, b.length); // Check null array refs + if (a == b) + return -1; + + for (int i = 0; i < length; i++) { + if (!Objects.equals(a[i], b[i])) + return i; + } + + return a.length != b.length ? length : -1; + } + + public static int mismatch( + Object[] a, int aFromIndex, int aToIndex, + Object[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + if (!Objects.equals(a[aFromIndex++], b[bFromIndex++])) + return i; + } + + return aLength != bLength ? length : -1; + } + + static void rangeCheck(int arrayLength, int fromIndex, int toIndex) { + if (fromIndex > toIndex) { + throw new IllegalArgumentException( + "fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")"); + } + if (fromIndex < 0) { + throw new ArrayIndexOutOfBoundsException(fromIndex); + } + if (toIndex > arrayLength) { + throw new ArrayIndexOutOfBoundsException(toIndex); + } + } + + @Test(disabled = true) + public static int test_ToArray(int execution) { + try { + checkMap(false); + checkMap(true); + checkSet(false); + checkSet(true); + } catch (Throwable t) { + return -1; + } + return execution; + } + + private static > void checkToArray(String message, T[] expected, Collection collection, + boolean ignoreOrder) { + if (ignoreOrder) { + Arrays.sort(expected); + } + checkToObjectArray(message, expected, collection, ignoreOrder); + checkToTypedArray(message, expected, Arrays.copyOf(expected, 0), collection, ignoreOrder); + checkToTypedArray(message, expected, expected.clone(), collection, ignoreOrder); + if (expected.length > 0) { + T[] biggerArray = Arrays.copyOf(expected, expected.length * 2); + System.arraycopy(expected, 0, biggerArray, expected.length, expected.length); + checkToTypedArray(message, expected, biggerArray, collection, ignoreOrder); + } + } + + private static > void checkToTypedArray(String message, T[] expected, T[] inputArray, + Collection collection, boolean ignoreOrder) { + T[] res = collection.toArray(inputArray); + if (expected.length <= inputArray.length && res != inputArray) { + throw new AssertionError(message + ": not the same array returned"); + } + if (res.getClass() != expected.getClass()) { + throw new AssertionError(message + ": wrong class returned: " + res.getClass()); + } + if (res.length < expected.length) { + throw new AssertionError(message + ": length is smaller than expected: " + res.length + " < " + expected.length); + } + if (ignoreOrder) { + Arrays.sort(res, 0, Math.min(res.length, expected.length)); + } + if (inputArray.length <= expected.length) { + if (!Arrays.equals(res, expected)) { + throw new AssertionError(message + ": not equal: " + Arrays.toString(expected) + " != " + + Arrays.toString(res)); + } + } else { + int mismatch = mismatch(expected, res); + if (mismatch != expected.length) { + throw new AssertionError(message + ": mismatch at " + mismatch); + } + if (res[expected.length] != null) { + throw new AssertionError(message + ": no null at position " + expected.length); + } + // The tail of bigger array after expected.length position must be untouched + mismatch = mismatch(expected, 1, expected.length, res, expected.length + 1, res.length); + if (mismatch != -1) { + throw new AssertionError(message + ": mismatch at " + mismatch); + } + } + } + + private static > void checkToObjectArray(String message, T[] expected, + Collection collection, boolean ignoreOrder) { + Object[] objects = collection.toArray(); + if (objects.getClass() != Object[].class) { + throw new AssertionError(message + ": wrong class returned: " + objects.getClass()); + } + if (ignoreOrder) { + Arrays.sort(objects); + } + int mismatch = mismatch(expected, objects); + if (mismatch != -1) { + throw new AssertionError(message + ": mismatch at " + mismatch); + } + } + + private static void checkMap(boolean ordered) { + Map map = ordered ? new LinkedHashMap<>() : new HashMap<>(); + checkToArray("Empty-keys", new String[0], map.keySet(), !ordered); + checkToArray("Empty-values", new String[0], map.values(), !ordered); + + List keys = new ArrayList<>(); + List values = new ArrayList<>(); + for (int i = 0; i < 100; i++) { + keys.add(String.valueOf(i)); + values.add(String.valueOf(i * 2)); + map.put(String.valueOf(i), String.valueOf(i * 2)); + checkToArray(i + "-keys", keys.toArray(new String[0]), map.keySet(), !ordered); + checkToArray(i + "-values", values.toArray(new String[0]), map.values(), !ordered); + } + map.clear(); + checkToArray("Empty-keys", new String[0], map.keySet(), !ordered); + checkToArray("Empty-values", new String[0], map.values(), !ordered); + } + + private static void checkSet(boolean ordered) { + Collection set = ordered ? new LinkedHashSet<>() : new HashSet<>(); + checkToArray("Empty", new String[0], set, !ordered); + set.add("foo"); + checkToArray("One", new String[]{"foo"}, set, !ordered); + set.add("bar"); + checkToArray("Two", new String[]{"foo", "bar"}, set, !ordered); + + Collection longSet = ordered ? new LinkedHashSet<>() : new HashSet<>(); + for (int x = 0; x < 100; x++) { + longSet.add((long) x); + } + checkToArray("100", LongStream.range(0, 100).boxed().toArray(Long[]::new), longSet, !ordered); + longSet.clear(); + checkToArray("After clear", new Long[0], longSet, !ordered); + for (int x = 0; x < 100; x++) { + longSet.add(((long) x) | (((long) x) << 32)); + } + checkToArray("Collisions", LongStream.range(0, 100).mapToObj(x -> x | (x << 32)) + .toArray(Long[]::new), longSet, !ordered); + } +} diff --git a/tests/src/main/java/approximations/java/util/map/HashMap/ToStringTest.java b/tests/src/main/java/approximations/java/util/map/HashMap/ToStringTest.java new file mode 100644 index 00000000..0723c90b --- /dev/null +++ b/tests/src/main/java/approximations/java/util/map/HashMap/ToStringTest.java @@ -0,0 +1,21 @@ +package approximations.java.util.map.HashMap; + +import approximations.Test; + +import java.util.HashMap; +import java.util.Map; + +@Test +public class ToStringTest { + @Test + public static int test_ToString(int execution) { + try { + Map m = new HashMap(); + m.put(null, null); + m.entrySet().iterator().next().toString(); + } catch (Throwable t) { + return -1; + } + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/map/HashMap/TreeBinAssertTest.java b/tests/src/main/java/approximations/java/util/map/HashMap/TreeBinAssertTest.java new file mode 100644 index 00000000..02195af2 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/map/HashMap/TreeBinAssertTest.java @@ -0,0 +1,164 @@ +package approximations.java.util.map.HashMap; + +import approximations.Test; + +import java.util.Map; +import java.util.Set; +import java.util.Iterator; +import java.util.HashMap; +import java.util.LinkedHashSet; + +@Test +public class TreeBinAssertTest { + private static final int ITR_RM = -1; + private static final int BIN352442_SIZE = 524288; + private static final int BIN552165_SIZE = 1048576; + + static int[][] sizeAndHashes = { + new int[] { + 2020958394, + 631595194, + 1984782522, + 419782842, + 285565114, + 1432182970, + 841310394, + 320692410, + 303390906, + ITR_RM, + ITR_RM, + ITR_RM, + ITR_RM, + ITR_RM, + ITR_RM, + ITR_RM, + ITR_RM, + 519397562, + ITR_RM, + 626352314, + 101540026 + }, + new int[] { + 790129893, + 1214803173, + 1212706021, + 608726245, + 2073586917, + 1433955557, + 692612325, + 370699493, + 2061004005, + 48786661, + ITR_RM, + ITR_RM, + 1418226917, + ITR_RM, + ITR_RM, + ITR_RM, + ITR_RM, + ITR_RM, + ITR_RM, + ITR_RM, + 1487432933, + ITR_RM, + ITR_RM, + 1880648933, + 338193637 + } + }; + + @Test(executionMax = 1) + public static int test_Map(int execution) { + if (!HashMap.class.desiredAssertionStatus()) { + return execution; + } + + int size; + int[] hashes; + if (execution == 0) { + size = BIN352442_SIZE; + hashes = sizeAndHashes[0]; + } else { + size = BIN552165_SIZE; + hashes = sizeAndHashes[1]; + } + + Map map = new HashMap<>(size); + + try { + Iterator itr = null; + for (int h : hashes) { + if (h == ITR_RM) { + if (itr == null) { + itr = map.keySet().iterator(); + } + itr.next(); + itr.remove(); + } else { + itr = null; + map.put(new Key(h), 0); + } + } + } catch (Throwable t) { + return -1; + } + + return execution; + } + + @Test(executionMax = 1) + public static int test_Set(int execution) { + if (!HashMap.class.desiredAssertionStatus()) { + return execution; + } + + int size; + int[] hashes; + if (execution == 0) { + size = BIN352442_SIZE; + hashes = sizeAndHashes[0]; + } else { + size = BIN552165_SIZE; + hashes = sizeAndHashes[1]; + } + + Set set = new LinkedHashSet<>(size); + + try { + Iterator itr = null; + for (int h : hashes) { + if (h == ITR_RM) { + if (itr == null) { + itr = set.iterator(); + } + itr.next(); + itr.remove(); + } else { + itr = null; + set.add(new Key(h)); + } + } + } catch (Throwable t) { + return -1; + } + return execution; + } + + static class Key implements Comparable { + final int hash; + + public Key(int desiredHash) { + this.hash = desiredHash ^ (desiredHash >>> 16); + } + + @Override public int hashCode() { return this.hash; } + + @Override public boolean equals(Object o) { + return o.hashCode() == this.hashCode(); + } + + @Override public int compareTo(Key k) { + return Integer.compare(this.hash, k.hash); + } + } +} diff --git a/tests/src/main/java/approximations/java/util/map/LinkedHashMap/BasicTest.java b/tests/src/main/java/approximations/java/util/map/LinkedHashMap/BasicTest.java new file mode 100644 index 00000000..af22f3b0 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/map/LinkedHashMap/BasicTest.java @@ -0,0 +1,110 @@ +package approximations.java.util.map.LinkedHashMap; + +import approximations.Test; + +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; + +@Test +public class BasicTest { + @Test + public static int test_Basic1(int execution) { + int nil = 0; + int numItr = 1; + int mapSize = 10; + for (int i=0; i m = new LinkedHashMap(); + int head = nil; + + for (int j=0; j m2 = new LinkedHashMap(); m2.putAll(m); + if (m2.size() != 10) { + return -1; + } + Set keySet = m.keySet(); + if (keySet.size() != 10) { + return -1; + } + m2.values().removeAll(m.keySet()); + if (m2.size() != 1 || !m2.containsValue(nil)) + return -1; + + int j=0; + while (head != nil) { + if (!m.containsKey(head)) + return -1; + Integer newHead = m.get(head); + if (newHead == null) + return -1; + m.remove(head); + head = newHead; + j++; + } + if (!m.isEmpty()) + return -1; + if (j != mapSize) + return -1; + } + + return execution; + } + + @Test + public static int test_Basic2(int execution) { + int nil = 0; + int mapSize = 10; + Map m = new LinkedHashMap(); + for (int i=0; i m2 = new LinkedHashMap(); m2.putAll(m); + if (!m.equals(m2)) + return -1; + if (!m2.equals(m)) + return -1; + Set> s = m.entrySet(), s2 = m2.entrySet(); + if (!s.equals(s2)) + return -1; + if (!s2.equals(s)) + return -1; + if (!s.containsAll(s2)) + return -1; + if (!s2.containsAll(s)) + return -1; + s2.removeAll(s); + if (!m2.isEmpty()) + return -1; + + m2.putAll(m); + m2.clear(); + if (!m2.isEmpty()) + return -1; + + Iterator it = m.entrySet().iterator(); + while (it.hasNext()) { + it.next(); + it.remove(); + } + if (!m.isEmpty()) + return -1; + + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/map/LinkedHashMap/CacheTest.java b/tests/src/main/java/approximations/java/util/map/LinkedHashMap/CacheTest.java new file mode 100644 index 00000000..7bff2263 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/map/LinkedHashMap/CacheTest.java @@ -0,0 +1,34 @@ +package approximations.java.util.map.LinkedHashMap; + +import approximations.Test; + +import java.util.LinkedHashMap; +import java.util.Map; + +@Test +public class CacheTest { + private static final int MAP_SIZE = 10; + private static final int NUM_KEYS = 100; + + @Test(disabled = true) + // TODO: LinkedHashMap can't currently handle removeEldestEntry + public static int test_Cache(int execution) { + try { + Map m = new LinkedHashMap() { + protected boolean removeEldestEntry(Map.Entry eldest) { + return size() > MAP_SIZE; + } + }; + + for (int i = 0; i < NUM_KEYS; i++) { + m.put(i, ""); // + int eldest = ((Integer) m.keySet().iterator().next()).intValue(); + if (eldest != Math.max(i - 9, 0)) + return -1; + } + } catch (Throwable t) { + return -1; + } + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/map/LinkedHashMap/ComputeIfAbsentAccessOrderTest.java b/tests/src/main/java/approximations/java/util/map/LinkedHashMap/ComputeIfAbsentAccessOrderTest.java new file mode 100644 index 00000000..972933d9 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/map/LinkedHashMap/ComputeIfAbsentAccessOrderTest.java @@ -0,0 +1,29 @@ +package approximations.java.util.map.LinkedHashMap; + +import approximations.Test; + +import java.util.LinkedHashMap; + +@Test +public class ComputeIfAbsentAccessOrderTest { + @Test + public static int test_ComputeIfAbsentAccessOrder(int execution) { + try { + LinkedHashMap map = new LinkedHashMap<>(2, 0.75f, true); + map.put("first", null); + map.put("second", null); + + map.computeIfAbsent("first", l -> null); + + String key = map.keySet().stream() + .findFirst() + .orElseThrow(() -> new RuntimeException("no value")); + if (!"first".equals(key) && !"second".equals(key)) { + return -1; + } + } catch (Throwable t) { + return -1; + } + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/map/LinkedHashMap/EmptyMapIteratorTest.java b/tests/src/main/java/approximations/java/util/map/LinkedHashMap/EmptyMapIteratorTest.java new file mode 100644 index 00000000..c538f51c --- /dev/null +++ b/tests/src/main/java/approximations/java/util/map/LinkedHashMap/EmptyMapIteratorTest.java @@ -0,0 +1,28 @@ +package approximations.java.util.map.LinkedHashMap; + +import approximations.Test; + +import java.util.ConcurrentModificationException; +import java.util.HashMap; +import java.util.Iterator; + +@Test +public class EmptyMapIteratorTest { + @Test + public static int test_EmptyMapIterator (int execution) { + try { + HashMap map = new HashMap(); + Iterator iter = map.entrySet().iterator(); + map.put("key", "value"); + + try { + iter.next(); + return -1; + } catch (ConcurrentModificationException e) { + } + } catch (Throwable t) { + return -1; + } + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/optional/BasicDoubleTest.java b/tests/src/main/java/approximations/java/util/optional/BasicDoubleTest.java new file mode 100644 index 00000000..8bfb4bd0 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/optional/BasicDoubleTest.java @@ -0,0 +1,186 @@ +package approximations.java.util.optional; + +import approximations.Test; + +import java.util.Arrays; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.OptionalDouble; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.DoubleStream; + +@Test +public class BasicDoubleTest { + static final double DOUBLEVAL = Math.PI; + static final double UNEXPECTED = 6.62607004E-34; + + /** + * Checks a block of assertions over an empty OptionalDouble. + */ + + public static DoubleStream OptionalDouble_stream(OptionalDouble optional) { + if (optional.isPresent()) { + return DoubleStream.of(optional.getAsDouble()); + } else { + return DoubleStream.empty(); + } + } + + static int checkEmpty(OptionalDouble empty, int execution) { + if (!empty.equals(OptionalDouble.empty())) { + return -1; + } + if (!OptionalDouble.empty().equals(empty)) { + return -1; + } + if (empty.equals(OptionalDouble.of(UNEXPECTED))) { + return -1; + } + if (OptionalDouble.of(UNEXPECTED).equals(empty)) { + return -1; + } + if (empty.equals("unexpected")) { + return -1; + } + + if (empty.isPresent()) { + return -1; + } + //if (!empty.isEmpty()); + if (empty.hashCode() != 0) { + return -1; + } + if (empty.orElse(UNEXPECTED) != UNEXPECTED) { + return -1; + } + if (empty.orElseGet(() -> UNEXPECTED) != UNEXPECTED) { + return -1; + } + + try { + empty.getAsDouble(); + return -1; + } catch (NoSuchElementException e) { + } + //assertThrows(NoSuchElementException.class, () -> empty.orElseThrow()); + //assertThrows(ObscureException.class, () -> empty.orElseThrow(ObscureException::new)); + + AtomicBoolean b = new AtomicBoolean(); + empty.ifPresent(s -> b.set(true)); + if (b.get()) { + return -1; + } + + AtomicBoolean b1 = new AtomicBoolean(false); + AtomicBoolean b2 = new AtomicBoolean(false); + empty.ifPresent(s -> b1.set(true)); + if (!b1.get()) { + b2.set(true); + } + if (b1.get()) { + return -1; + } + if (!b2.get()) { + return -1; + } + + if (empty.toString() != "OptionalDouble.empty") { + return -1; + } + return execution; + } + + /** + * Checks a block of assertions over an OptionalDouble that is expected to + * have a particular value present. + */ + static int checkPresent(OptionalDouble opt, double expected, int execution) { + if (opt.equals(OptionalDouble.empty())) { + return -1; + } + if (OptionalDouble.empty().equals(opt)) { + return -1; + } + if (!opt.equals(OptionalDouble.of(expected))) { + return -1; + } + if (!OptionalDouble.of(expected).equals(opt)) { + return -1; + } + if (opt.equals(OptionalDouble.of(UNEXPECTED))) { + return -1; + } + if (OptionalDouble.of(UNEXPECTED).equals(opt)) { + return -1; + } + if (opt.equals("unexpected")) { + return -1; + } + + if (!opt.isPresent()) { + return -1; + } + if (opt.orElse(UNEXPECTED) != expected) { + return -1; + } + if (opt.orElseGet(() -> UNEXPECTED) != expected) { + return -1; + } + + if (opt.getAsDouble() != expected) { + return -1; + } + + AtomicBoolean b = new AtomicBoolean(false); + opt.ifPresent(s -> b.set(true)); + if (!b.get()) { + return -1; + } + + AtomicBoolean b1 = new AtomicBoolean(false); + AtomicBoolean b2 = new AtomicBoolean(false); + opt.ifPresent(s -> b1.set(true)); + if (!b1.get()) { + b2.set(true); + } + if (!b1.get()) { + return -1; + } + if (b2.get()) { + return -1; + } + + String optToString = opt.toString(); + //String test = String.valueOf(expected); + if (!optToString.equals("OptionalDouble[" + expected + "]")) { + return -1; + } + return execution; + } + + @Test(disabled = true) + public static int test_Empty(int execution) { + return checkEmpty(OptionalDouble.empty(), execution); + } + + @Test + public static int test_Present(int execution) { + return checkPresent(OptionalDouble.of(DOUBLEVAL), DOUBLEVAL, execution); + } + + @Test(disabled = true) + public static int test_StreamEmpty(int execution) { + if (!Arrays.equals(OptionalDouble_stream(OptionalDouble.empty()).toArray(), new double[]{})) { + return -1; + } + return execution; + } + + @Test(disabled = true) + public static int test_StreamPresent (int execution) { + if (!Arrays.equals(OptionalDouble_stream(OptionalDouble.of(DOUBLEVAL)).toArray(), new double[]{DOUBLEVAL})) { + return -1; + } + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/optional/BasicIntTest.java b/tests/src/main/java/approximations/java/util/optional/BasicIntTest.java new file mode 100644 index 00000000..46029835 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/optional/BasicIntTest.java @@ -0,0 +1,182 @@ +package approximations.java.util.optional; + +import approximations.Test; + +import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.DoubleStream; +import java.util.stream.IntStream; + +@Test +public class BasicIntTest { + static final int INTVAL = 33_550_336; + static final int UNEXPECTED = 0xCAFEBABE; + + /** + * Checks a block of assertions over an empty OptionalInt. + */ + + public static IntStream OptionalInt_stream(OptionalInt optional) { + if (optional.isPresent()) { + return IntStream.of(optional.getAsInt()); + } else { + return IntStream.empty(); + } + } + + static int checkEmpty(OptionalInt empty, int execution) { + if (!empty.equals(OptionalInt.empty())) { + return -1; + } + if (!OptionalInt.empty().equals(empty)) { + return -1; + } + if (empty.equals(OptionalInt.of(UNEXPECTED))) { + return -1; + } + if (OptionalInt.of(UNEXPECTED).equals(empty)) { + return -1; + } + if (empty.equals("unexpected")) { + return -1; + } + + if (empty.isPresent()) { + return -1; + } + //if (!empty.isEmpty()); + if (empty.hashCode() != 0) { + return -1; + } + if (empty.orElse(UNEXPECTED) != UNEXPECTED) { + return -1; + } + if (empty.orElseGet(() -> UNEXPECTED) != UNEXPECTED) { + return -1; + } + + try { + empty.getAsInt(); + return -1; + } catch (NoSuchElementException e) { + } + //assertThrows(NoSuchElementException.class, () -> empty.orElseThrow()); + //assertThrows(ObscureException.class, () -> empty.orElseThrow(ObscureException::new)); + + AtomicBoolean b = new AtomicBoolean(); + empty.ifPresent(s -> b.set(true)); + if (b.get()) { + return -1; + } + + AtomicBoolean b1 = new AtomicBoolean(false); + AtomicBoolean b2 = new AtomicBoolean(false); + empty.ifPresent(s -> b1.set(true)); + if (!b1.get()) { + b2.set(true); + } + if (b1.get()) { + return -1; + } + if (!b2.get()) { + return -1; + } + + if (empty.toString() != "OptionalInt.empty") { + return -1; + } + return execution; + } + + /** + * Checks a block of assertions over an OptionalInt that is expected to + * have a particular value present. + */ + static int checkPresent(OptionalInt opt, int expected, int execution) { + if (opt.equals(OptionalInt.empty())) { + return -1; + } + if (OptionalInt.empty().equals(opt)) { + return -1; + } + if (!opt.equals(OptionalInt.of(expected))) { + return -1; + } + if (!OptionalInt.of(expected).equals(opt)) { + return -1; + } + if (opt.equals(OptionalInt.of(UNEXPECTED))) { + return -1; + } + if (OptionalInt.of(UNEXPECTED).equals(opt)) { + return -1; + } + if (opt.equals("unexpected")) { + return -1; + } + + if (!opt.isPresent()) { + return -1; + } + if (opt.orElse(UNEXPECTED) != expected) { + return -1; + } + if (opt.orElseGet(() -> UNEXPECTED) != expected) { + return -1; + } + + if (opt.getAsInt() != expected) { + return -1; + } + + AtomicBoolean b = new AtomicBoolean(false); + opt.ifPresent(s -> b.set(true)); + if (!b.get()) { + return -1; + } + + AtomicBoolean b1 = new AtomicBoolean(false); + AtomicBoolean b2 = new AtomicBoolean(false); + opt.ifPresent(s -> b1.set(true)); + if (!b1.get()) { + b2.set(true); + } + if (!b1.get()) { + return -1; + } + if (b2.get()) { + return -1; + } + + /*if (opt.toString() != "OptionalInt[" + expected + "]") { + return -1; + }*/ + return execution; + } + + @Test + public static int test_Empty(int execution) { + return checkEmpty(OptionalInt.empty(), execution); + } + + @Test + public static int test_Present(int execution) { + return checkPresent(OptionalInt.of(INTVAL), INTVAL, execution); + } + + @Test(disabled = true) + public static int test_StreamEmpty(int execution) { + if (!Arrays.equals(OptionalInt_stream(OptionalInt.empty()).toArray(), new int[]{})) { + return -1; + } + return execution; + } + + @Test(disabled = true) + public static int test_StreamPresent(int execution) { + if (!Arrays.equals(OptionalInt_stream(OptionalInt.of(INTVAL)).toArray(), new int[]{INTVAL})) { + return -1; + } + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/optional/BasicLongTest.java b/tests/src/main/java/approximations/java/util/optional/BasicLongTest.java new file mode 100644 index 00000000..f08e95e6 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/optional/BasicLongTest.java @@ -0,0 +1,187 @@ +package approximations.java.util.optional; + +import approximations.Test; + +import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.IntStream; +import java.util.stream.LongStream; + +public class BasicLongTest { + static final long LONGVAL = 2_305_843_008_139_952_128L; + static final long UNEXPECTED = 0xFEEDBEEFCAFEBABEL; + + /** + * Checks a block of assertions over an empty OptionalLong. + */ + + public static LongStream OptionalLong_stream(OptionalLong optional) { + if (optional.isPresent()) { + return LongStream.of(optional.getAsLong()); + } else { + return LongStream.empty(); + } + } + + static int checkEmpty(OptionalLong empty, int execution) { + if (!empty.equals(OptionalLong.empty())) { + return -1; + } + if (!OptionalLong.empty().equals(empty)) { + return -1; + } + if (empty.equals(OptionalLong.of(UNEXPECTED))) { + return -1; + } + if (OptionalLong.of(UNEXPECTED).equals(empty)) { + return -1; + } + if (empty.equals("unexpected")) { + return -1; + } + + if (empty.isPresent()) { + return -1; + } + //if (!empty.isEmpty()); + if (empty.hashCode() != 0) { + return -1; + } + if (empty.orElse(UNEXPECTED) != UNEXPECTED) { + return -1; + } + if (empty.orElseGet(() -> UNEXPECTED) != UNEXPECTED) { + return -1; + } + + try { + empty.getAsLong(); + return -1; + } catch (NoSuchElementException e) { + } + //assertThrows(NoSuchElementException.class, () -> empty.orElseThrow()); + //assertThrows(ObscureException.class, () -> empty.orElseThrow(ObscureException::new)); + + AtomicBoolean b = new AtomicBoolean(); + empty.ifPresent(s -> b.set(true)); + if (b.get()) { + return -1; + } + + AtomicBoolean b1 = new AtomicBoolean(false); + AtomicBoolean b2 = new AtomicBoolean(false); + empty.ifPresent(s -> b1.set(true)); + if (!b1.get()) { + b2.set(true); + } + if (b1.get()) { + return -1; + } + if (!b2.get()) { + return -1; + } + + if (empty.toString() != "OptionalLong.empty") { + return -1; + } + return execution; + } + + /** + * Checks a block of assertions over an OptionalLong that is expected to + * have a particular value present. + */ + static int checkPresent(OptionalLong opt, long expected, int execution) { + if (opt.equals(OptionalLong.empty())) { + return -1; + } + if (OptionalLong.empty().equals(opt)) { + return -1; + } + if (!opt.equals(OptionalLong.of(expected))) { + return -1; + } + if (!OptionalLong.of(expected).equals(opt)) { + return -1; + } + if (opt.equals(OptionalLong.of(UNEXPECTED))) { + return -1; + } + if (OptionalLong.of(UNEXPECTED).equals(opt)) { + return -1; + } + if (opt.equals("unexpected")) { + return -1; + } + + if (!opt.isPresent()) { + return -1; + } + //assertFalse(opt.isEmpty()); + /*if (opt.hashCode() != Long.hashCode(expected)) { + return -1; + }*/ + if (opt.orElse(UNEXPECTED) != expected) { + return -1; + } + if (opt.orElseGet(() -> UNEXPECTED) != expected) { + return -1; + } + + if (opt.getAsLong() != expected) { + return -1; + } + //assertEquals(opt.orElseThrow(), expected); + //assertEquals(opt.orElseThrow(ObscureException::new), expected); + + AtomicBoolean b = new AtomicBoolean(false); + opt.ifPresent(s -> b.set(true)); + if (!b.get()) { + return -1; + } + + AtomicBoolean b1 = new AtomicBoolean(false); + AtomicBoolean b2 = new AtomicBoolean(false); + opt.ifPresent(s -> b1.set(true)); + if (!b1.get()) { + b2.set(true); + } + if (!b1.get()) { + return -1; + } + if (b2.get()) { + return -1; + } + + /*if (opt.toString() != "OptionalLong[" + expected + "]") { + return -1; + }*/ + return execution; + } + + @Test + public static int test_Empty(int execution) { + return checkEmpty(OptionalLong.empty(), execution); + } + + @Test + public static int test_Present(int execution) { + return checkPresent(OptionalLong.of(LONGVAL), LONGVAL, execution); + } + + @Test(disabled = true) + public static int test_StreamEmpty(int execution) { + if (!Arrays.equals(OptionalLong_stream(OptionalLong.empty()).toArray(), new long[]{})) { + return -1; + } + return execution; + } + + @Test(disabled = true) + public static int test_StreamPresent(int execution) { + if (!Arrays.equals(OptionalLong_stream(OptionalLong.of(LONGVAL)).toArray(), new long[]{LONGVAL})) { + return -1; + } + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/optional/BasicTest.java b/tests/src/main/java/approximations/java/util/optional/BasicTest.java new file mode 100644 index 00000000..9cb9abca --- /dev/null +++ b/tests/src/main/java/approximations/java/util/optional/BasicTest.java @@ -0,0 +1,330 @@ +package approximations.java.util.optional; + +import approximations.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Stream; + +import static java.util.stream.Collectors.toList; + +@Test +public class BasicTest { + public static Stream Optional_stream(Optional optional) { + if (!optional.isPresent()) { + return Stream.empty(); + } else { + return Stream.of(optional.get()); + } + } + + public static List List_of() { + return new ArrayList(); + } + + public static List List_of(T element) { + ArrayList list = new ArrayList(); + list.add(element); + return list; + } + + static int checkEmpty(Optional empty, int execution) { + if (!empty.equals(Optional.empty())) { + return -1; + } + if (!Optional.empty().equals(empty)) { + return -1; + } + if (empty.equals(Optional.of("unexpected"))) { + return -1; + } + if (Optional.of("unexpected").equals(empty)) { + return -1; + } + if (empty.equals("unexpected")) { + return -1; + } + + if (empty.isPresent()) { + return -1; + } + //if (!empty.isEmpty()); + if (empty.hashCode() != 0) { + return -1; + } + if (empty.orElse("x") != "x") { + return -1; + } + if (empty.orElseGet(() -> "y") != "y") { + return -1; + } + + try { + empty.get(); + return -1; + } catch (NoSuchElementException e) { + } + //assertThrows(NoSuchElementException.class, () -> empty.orElseThrow()); + //assertThrows(ObscureException.class, () -> empty.orElseThrow(ObscureException::new)); + + AtomicBoolean b = new AtomicBoolean(); + empty.ifPresent(s -> b.set(true)); + if (b.get()) { + return -1; + } + + AtomicBoolean b1 = new AtomicBoolean(false); + AtomicBoolean b2 = new AtomicBoolean(false); + empty.ifPresent(s -> b1.set(true)); + if (!b1.get()) { + b2.set(true); + } + if (b1.get()) { + return -1; + } + if (!b2.get()) { + return -1; + } + + if (empty.toString() != "Optional.empty") { + return -1; + } + return execution; + } + + /** + * Checks a block of assertions over an Optional that is expected to + * have a particular value present. + */ + static int checkPresent(Optional opt, String expected, int execution) { + if (opt.equals(Optional.empty())) { + return -1; + } + if (Optional.empty().equals(opt)) { + return -1; + } + if (!opt.equals(Optional.of(expected))) { + return -1; + } + if (!Optional.of(expected).equals(opt)) { + return -1; + } + if (opt.equals(Optional.of("unexpected"))) { + return -1; + } + if (Optional.of("unexpected").equals(opt)) { + return -1; + } + if (opt.equals("unexpected")) { + return -1; + } + + if (!opt.isPresent()) { + return -1; + } + //assertFalse(opt.isEmpty()); + /*if (opt.hashCode() != expected.hashCode()) { + return -1; + }*/ + if (opt.orElse("unexpected") != expected) { + return -1; + } + if (opt.orElseGet(() -> "unexpected") != expected) { + return -1; + } + + if (opt.get() != expected) { + return -1; + } + //if (opt.orElseThrow() != expected); + //if (opt.orElseThrow(ObscureException::new), expected); + + AtomicBoolean b = new AtomicBoolean(false); + opt.ifPresent(s -> b.set(true)); + if (!b.get()) { + return -1; + } + + AtomicBoolean b1 = new AtomicBoolean(false); + AtomicBoolean b2 = new AtomicBoolean(false); + opt.ifPresent(s -> b1.set(true)); + if (!b1.get()) { + b2.set(true); + } + if (!b1.get()) { + return -1; + } + if (b2.get()) { + return -1; + } + + /*if (opt.toString() != "Optional[" + expected + "]") { + return -1; + }*/ + return execution; + } + + @Test + public static int test_Empty (int execution) { + return checkEmpty(Optional.empty(), execution); + } + + @Test + public static int test_OfNull (int execution) { + try { + Optional.of(null); + return -1; + } catch (NullPointerException e) { + return execution; + } + } + + @Test + public static int test_OfPresent(int execution) { + return checkPresent(Optional.of("xyzzy"), "xyzzy", execution); + } + + @Test + public static int test_OfNullableNull(int execution) { + return checkEmpty(Optional.ofNullable(null), execution); + } + + @Test + public static int test_OfNullablePresent(int execution) { + return checkPresent(Optional.ofNullable("xyzzy"), "xyzzy", execution); + } + + @Test + public static int test_FilterEmpty(int execution) { + AtomicBoolean failed = new AtomicBoolean(false); + int result = checkEmpty(Optional.empty().filter(s -> { failed.set(true); return true; }), execution); + if (failed.get()) { + return -1; + } else { + return result; + } + } + + @Test + public static int test_FilterFalse(int execution) { + return checkEmpty(Optional.of("xyzzy").filter(s -> s.equals("plugh")), execution); + } + + @Test + public static int test_FilterTrue(int execution) { + return checkPresent(Optional.of("xyzzy").filter(s -> s.equals("xyzzy")), "xyzzy", execution); + } + + @Test + public static int test_MapEmpty(int execution) { + AtomicBoolean failed = new AtomicBoolean(false); + int result = checkEmpty(Optional.empty().map(s -> { failed.set(true); return ""; }), execution); + if (failed.get()) { + return -1; + } else { + return result; + } + } + + @Test + public static int test_MapPresent(int execution) { + return checkPresent(Optional.of("xyzzy").map(s -> s.replace("xyzzy", "plugh")), + "plugh", execution); + } + + @Test + public static int test_FlatMapEmpty(int execution) { + AtomicBoolean failed = new AtomicBoolean(false); + int result = checkEmpty(Optional.empty().flatMap(s -> { failed.set(true); return Optional.of(""); }), + execution); + if (failed.get()) { + return -1; + } else { + return result; + } + } + + @Test + public static int test_FlatMapPresentReturnEmpty(int execution) { + AtomicBoolean failed = new AtomicBoolean(false); + int result = checkEmpty(Optional.of("xyzzy") + .flatMap(s -> { + if (s != "xyzzy") { + failed.set(true); + } + return Optional.empty(); + }), execution); + if (failed.get()) { + return -1; + } else { + return result; + } + } + + @Test + public static int test_FlatMapPresentReturnPresent(int execution) { + AtomicBoolean failed = new AtomicBoolean(false); + int result = checkPresent(Optional.of("xyzzy") + .flatMap(s -> { + if (s != "xyzzy") { + failed.set(true); + } + return Optional.of("plugh"); + }), + "plugh", execution); + if (failed.get()) { + return -1; + } else { + return result; + } + } + + @Test + public static int test_OrEmptyEmpty(int execution) { + try { + Optional.empty().get(); + return -1; + } catch (NoSuchElementException e) { + return checkEmpty(Optional.empty(), execution); + } + } + + @Test + public static int test_OrEmptyPresent(int execution) { + try { + Optional.empty().get(); + return -1; + } catch (NoSuchElementException e) { + return checkPresent(Optional.of("plugh"), "plugh", execution); + } + } + + @Test + public static int test_OrPresentDontCare(int execution) { + Optional optional = Optional.of("xyzzy"); + if (optional.isPresent()) { + return checkPresent(optional, "xyzzy", execution); + } else { + return -1; + } + } + + @Test(disabled = true) + public static int testStreamEmpty(int execution) { + if (Optional_stream(Optional.empty()).collect(toList()) != List_of()) { + return -1; + } + return execution; + } + + @Test(disabled = true) + public static int testStreamPresent(int execution) { + if (Optional_stream(Optional.of("xyzzy")).collect(toList()) != List_of("xyzzy")) { + return -1; + } + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/set/HashSet_Tests.java b/tests/src/main/java/approximations/java/util/set/HashSet_Tests.java new file mode 100644 index 00000000..6993e85f --- /dev/null +++ b/tests/src/main/java/approximations/java/util/set/HashSet_Tests.java @@ -0,0 +1,61 @@ +package approximations.java.util.set; + +import approximations.Test; + +import java.util.HashSet; +import java.util.Random; + +@Test +public class HashSet_Tests { + private static final int NUM_SETS = 1; + private static final int MAX_CAPACITY = 2; + + //private static final Random rnd = new Random(); + + /*private static HashSet createHashSet() { + + HashSet hashSet = new HashSet<>(); + for (int i = 0; i < MAX_CAPACITY; i++) { + hashSet.add(rnd.nextInt()); + } + return hashSet; + }*/ + + @Test + public static int test_SetClone1(int execution) { + for (int i = 0; i < NUM_SETS; i++) { + //HashSet hashSet = createHashSet(); + HashSet hashSet = new HashSet<>(); + Random rnd = new Random(); + for (int j = 0; j < MAX_CAPACITY; j++) { + hashSet.add(rnd.nextInt()); + } + + HashSet result = (HashSet) hashSet.clone(); + + if (!hashSet.equals(result)) { + return -1; + } + } + return execution; + } + + @Test + public static int test_SetClone2(int execution) { + for (int i = 0; i < NUM_SETS; i++) { + //HashSet hashSet = createHashSet(); + HashSet hashSet = new HashSet<>(); + Random rnd = new Random(); + for (int j = 0; j < MAX_CAPACITY; j++) { + hashSet.add(rnd.nextDouble()); + } + + HashSet result = (HashSet) hashSet.clone(); + + if (!hashSet.equals(result)) { + return -1; + } + } + return execution; + } +} diff --git a/tests/src/main/java/approximations/java/util/set/LinkedHashSet_Tests.java b/tests/src/main/java/approximations/java/util/set/LinkedHashSet_Tests.java new file mode 100644 index 00000000..5362b805 --- /dev/null +++ b/tests/src/main/java/approximations/java/util/set/LinkedHashSet_Tests.java @@ -0,0 +1,196 @@ +package approximations.java.util.set; + +import approximations.Test; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.Set; + +@Test +public class LinkedHashSet_Tests { + static final int numItr = 1; + static final int setSize = 10; + + @Test + // TODO: wrong size after union() + public static int test_LinkedHashSet1(int execution) throws Exception { + for (int i=0; i s1 = new LinkedHashSet<>(); + AddNumbers(s1, 1); + + Set s2 = new LinkedHashSet<>(); + AddNumbers(s2, 6); + + try { + Set intersection = clone1(s1); + intersection.retainAll(s2); + Set diff1 = clone1(s1); + diff1.removeAll(s2); + Set diff2 = clone1(s2); + diff2.removeAll(s1); + Set union = clone1(s1); + union.addAll(s2); + + if (diff1.removeAll(diff2)) + return -1; + if (diff1.removeAll(intersection)) + return -1; + if (diff2.removeAll(diff1)) + return -1; + if (diff2.removeAll(intersection)) + return -1; + if (intersection.removeAll(diff1)) + return -1; + if (intersection.removeAll(diff1)) + return -1; + + intersection.addAll(diff1); + intersection.addAll(diff2); + /*if (!intersection.equals(union)) + return -1;*/ + if (intersection.size() != 15) { + return -1; + } + if (union.size() != 20) { + return -1; + } + + /*Iterator e = union.iterator(); + while (e.hasNext()) + if (!intersection.remove(e.next())) + return -1; + if (!intersection.isEmpty()) + return -1; + + e = union.iterator(); + while (e.hasNext()) { + Object o = e.next(); + if (!union.contains(o)) + return -1; + e.remove(); + if (union.contains(o)) + return -1; + } + if (!union.isEmpty()) + return -1; + + s1.clear(); + if (!s1.isEmpty()) + return -1;*/ + } catch (Exception e) { + return -1; + } + } + return execution; + } + + @Test + public static int test_LinkedHashSet2(int execution) throws Exception { + for (int i=0; i clone1(Set s) throws Exception { + Set clone; + clone = (Set) ((LinkedHashSet) s).clone(); + if (!s.equals(clone)) + throw new Exception("Set not equal to copy: "); + if (!s.containsAll(clone)) + throw new Exception("Set does not contain copy."); + if (!clone.containsAll(s)) + throw new Exception("Copy does not contain set."); + return clone; + } + + static Set clone2(Set s) throws Exception { + Set clone; + clone = new LinkedHashSet(Arrays.asList(s.toArray())); + if (!s.equals(clone)) + throw new Exception("Set not equal to copy: "); + if (!s.containsAll(clone)) + throw new Exception("Set does not contain copy."); + if (!clone.containsAll(s)) + throw new Exception("Copy does not contain set."); + return clone; + } + + static void AddNumbers(Set s, int minElem) throws Exception { + for (int i = 0; i < setSize; i++) { + Integer e = minElem + i; + + int preSize = s.size(); + boolean prePresent = s.contains(e); + boolean added = s.add(e); + if (!s.contains(e)) + throw new Exception("Element not present after addition."); + if (added == prePresent) + throw new Exception("added == alreadyPresent"); + int postSize = s.size(); + if (added && preSize == postSize) + throw new Exception("Add returned true, but size didn't change."); + if (!added && preSize != postSize) + throw new Exception("Add returned false, but size changed."); + } + } +} diff --git a/usvm-api/usvm-api.jar b/usvm-api/usvm-api.jar index f596e33f..fb9607f8 100644 Binary files a/usvm-api/usvm-api.jar and b/usvm-api/usvm-api.jar differ